E N D
DUE NOW • Lab 9 - resistances
Your task.. • Create a program that allows the user to enter as many individual resistance values (in Ohms) as the user wants. When the user wants to stop entering values, s/he will enter a negative or zero value. When done, tell the user the equivalent value in both series and parallel. DO NOT USE ARRAYS or material not taught. Use material taught in the lecture yesterday.
The series shouldn’t even be worth any points… • Example from the slides (last Thursday and yesterday!) • Equation for the lab • What repeats?
That part is easy (if you practice the slides) %surface counting %by Dr. Pembridge clc clear % prompt for a surface (and give directions) fprintf('Note: a negative/zero surface quits.\n'); surface = input('Enter surface (m2): '); sumSurfaces = 0; %start result at zero % while surface is positive while surface>0 % “running total”: add surfaces as they are given sumSurfaces = sumSurfaces + surface; % ask for next surface value surface = input('Next surface: '); end % display total surface to the screen fprintf('All the surfaces add up to %.4f m2.\n', sumSurfaces);
That part is easy (if you practice the slides) %resistance counting %by Caroline clc clear % prompt for a resistance (and give directions) fprintf('Note: a negative/zero resistance quits.\n'); resistance = input('Enter resistance (Ohms): '); sumResistances= 0; %start result at zero % while resistance is positive whileresistance >0 % calculate series setup sumResistances= sumResistances+ resistance; % ask for next resistance value resistance = input('Next resistance: '); end % display total resistance to the screen fprintf('All the resistances (series) add up to %.4f Ohms.\n', sumResistances);
Test as you go… %resistance counting %by Caroline clc clear % prompt for a resistance (and give directions) fprintf('Note: a negative/zero resistance quits.\n'); resistance = input('Enter resistance (Ohms): '); sumResistances = 0; %start result at zero % while resistance is positive whileresistance >0 % calculate series setup sumResistances= sumResistances+ resistance ; % ask for next resistance value resistance = input('Next resistance: '); end % display total resistance to the screen fprintf('All the resistances (series) add up to %.4f m2.\n', sumResistances); ugh.. I need to skip lines in the output..
About the parallel.. • Don’t try to simplify the equation • the simple fact that we don’t have ALL resistance values from the start prevents ANY simplification anyways! • Instead, find WHAT repeats and WHAT doesn’t! below the loop inside the loop
Implement 3 more lines… % prompt for a resistance (and give directions) fprintf('Note: a negative/zero resistance quits.\n'); resistance = input('Enter resistance (Ohms): '); sumResistances= 0; %start result at zero denominator = 0; %start denominator at zero % while resistance is positive whileresistance >0 % calculate series setup sumResistances= sumResistances+ resistance; % calculate parallel setup denominator = denominator + 1/resistance; % ask for next resistance value resistance = input('Next resistance: '); end % display both resistance equivalent to the screen fprintf(‘\nAllthe resistances (series) add up to %.4f Ohms.\n', sumResistances); fprintf('and in parallel, it''ll be equivalent to %.4f Ohms.\n', 1/denominator);
For those adventurous ones… • Add a little bit! % prompt for a resistance (and give directions) fprintf('Note: a negative/zero resistance quits.\n'); resistance = input('Enter first resistance (Ohms): '); sumResistances = 0; %start result at zero denominator = 0; %start denominator at zero res_nb = 2; %start counter to display 2nd in loop..etc % while resistance is positive whileresistance >0 % calculate series setup sumResistances = sumResistances + resistance ; % calculate parallel setup denominator = denominator + 1/resistance; % ask for next resistance value fprintf('Enter resistance #%d: ',res_nb); resistance = input(''); res_nb = res_nb+1; %update for next loop end % display both resistance equivalent to the screen fprintf('\nAll the resistances (series) add up to %.4f Ohms.\n', sumResistances); fprintf('and in parallel, it''ll be equivalent to %.4f Ohms.\n', 1/denominator);
TEST!!! • Add a little bit! % prompt for a resistance (and give directions) fprintf('Note: a negative/zero resistance quits.\n'); resistance = input('Enter first resistance (Ohms): '); sumResistances = 0; %start result at zero denominator = 0; %start denominator at zero res_nb = 2; %start counter to display 2nd in loop..etc % while resistance is positive whileresistance >0 % calculate series setup sumResistances = sumResistances + resistance ; % calculate parallel setup denominator = denominator + 1/resistance; % ask for next resistance value fprintf('Enter resistance #%d: ',res_nb); resistance = input(''); res_nb = res_nb+1; %update for next loop end % display both resistance equivalent to the screen fprintf('\nAll the resistances (series) add up to %.4f Ohms.\n', sumResistances); fprintf('and in parallel, it''ll be equivalent to %.4f Ohms.\n', 1/denominator);
A variety of engineering… • Lab02 – Math (Do 2 lines intersect?) • Lab03/04 – Math (land purchase) & Civil (buckling) • Lab05 – Civil (buckling) & Fluids (Flow through pipe) • Lab06 – Civil/Aero (buckling & cement ratio) • Practice Exam1 – Math & Environmental (Heating House) • Exam1 – Environmental (Windmill) • Lab08 – Math (tiles) • Lab09 – Electrical (resistances) • Lab10 – Mechanical (reduction gears)
Reduction gears • reduction gear - gearing that reduces an input speed to a slower output speed.
Math is rather simple… • Some gears are “drivers”, others are “driven” • Gears 1,3,5 are called “Drivers” since they drive the other gears. • Gears 2,4,6 are called “Driven” since they are driven by the other gears. • Given an input speed ( “omega” in rad/s), the output speed is: 1 3 5 2 4 6
Your task… • Prompt the user for the input angular velocity (in radians/sec). Check validity! Trap the user while invalid. • Prompt the user for the total number of gears. Check validity as well. The client requires more than 4 gears at all times. • Use a for loop to prompt for the number of teeth on each gear. Assume the user enters valid numbers of teeth at this time, and again alternates appropriately. • Complete calculations properly, and display the value of with 1 decimal place. • Use an if statement to indicate in which direction the last gear rotates compared to gear #1. Tons of Bonus ideas possible here! Just make sure to code it in a separate file. Zip and submit and print both in that case. Use your imagination!