0% found this document useful (0 votes)
30 views2 pages

MATLAB Simulation of Ohm's Law

This document provides a step-by-step guide on using MATLAB to demonstrate Ohm's Law by plotting voltage against current for a defined resistance. It includes instructions for defining variables, plotting results, and experimenting with different resistance values. The final output is a visual representation of how voltage changes with varying current and resistance.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

MATLAB Simulation of Ohm's Law

This document provides a step-by-step guide on using MATLAB to demonstrate Ohm's Law by plotting voltage against current for a defined resistance. It includes instructions for defining variables, plotting results, and experimenting with different resistance values. The final output is a visual representation of how voltage changes with varying current and resistance.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Step 1: Open MATLAB

Launch MATLAB and open a new script or use the command window.

Step 2: Define Variables

We define a range of resistance (RRR) and current (III) values.

% Define resistance (Ohms)


R = 10; % You can change this value

% Define current (Amps)


I = 0:0.1:10; % Creating a range of current from 0A to 10A with a step of 0.1A

% Calculate Voltage using Ohm’s Law


V = I * R;

Step 3: Plot the Results

To visualize the relationship between current and voltage:

% Plot Voltage vs. Current


plot(I, V, 'b', 'LineWidth', 2);
grid on;

% Add labels and title


xlabel('Current (A)');
ylabel('Voltage (V)');
title('Ohm’s Law: Voltage vs. Current');
legend(['R = ' num2str(R) ' \Omega']);

Step 4: Run the Script

Save the script (e.g., ohms_law.m) and run it in MATLAB. The plot will show a straight line,
confirming that voltage increases linearly with current for a constant resistance.

Step 5: Experiment with Different Values

Try modifying R to different values and observe how the voltage changes.

Example with Multiple Resistances:

% Define multiple resistances


R_values = [5, 10, 15];

% Plot for each resistance


figure;
hold on;
for R = R_values
V = I * R;
plot(I, V, 'LineWidth', 2);
end
hold off;

% Labels and title


xlabel('Current (A)');
ylabel('Voltage (V)');
title('Ohm’s Law for Different Resistances');
legend('R = 5 \Omega', 'R = 10 \Omega', 'R = 15 \Omega');
grid on;

This script will plot multiple lines showing how voltage changes for different resistances.

You might also like