Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please solve the problem by using Matlab Now it\'s your turn. Write a script to

ID: 1995916 • Letter: P

Question

Please solve the problem by using Matlab

Now it's your turn. Write a script to make a proper plot for Ohm's Law, V = IR, for currents ranging from 2A to 20A in steps of 2 and resistance values R_1 = 9 Ohm and R_2 = 19 Ohm. Resist the temptation to play MAT LAB golf. Just because you can write it a small amount of code does mean you should. Make your plan first, then implement it step-by-step. Remember, a proper plot has A title Axis labels A legend Differently colored lines with distinguishable line styles Experimental data as points (not connected by lines) Theoretical or model values as lines (solid, dashed, etc.) For example, your finished plot should look something like the following, although it need not be the same.

Explanation / Answer

%MATLAB CODE FOR PLOTTING VOLTAGE VERSUS CURRENT FOR DIFFERENT VALUES OF RESISTANCE

i=2:2:20; %INITIALISE A CURRENT VECTOR
r1=9; r2=19; %INITIALIZE THE VALUES OF RESISTANCE
v1=i*r1;
v2=i*r2; %GET THE VOLTAGE VECTORS FOR THE TWO VALUES OF RESISTANCE

plot(i,v1,'-bo','LineWidth', 2) %PLOT THE VOLTAGE VS. CURRENT FOR FIRST RESISTANCE VALUE
hold; %HOLD THE PLOT TO ADD ANOTHER ONE
plot(i,v2, '-r*','LineWidth', 2)%PLOT THE VOLTAGE VS CURRENT FOR SECOND RESISTSANCE VALUE
legend('9 ohms','19 ohms') %SET THE LEGEND TABLE
title('plot of voltage versus current for different values of resistance')%TITLE OF THE PLOT
xlabel('Current (A)');
ylabel('Voltage (V)'); %SET THE LABELS FOR BOTH THE AXES