# MATLAB, Understanding the occurence of multiple lines for t=0:0.1:10*pi ?

Status
Not open for further replies.

#### vetriece86@gmail.com

##### Junior Member level 2
Hi all,

*At t=0:0.1:10*pi,*

In matlab, I am getting multiple lines at v=1.5 and v=-1.5 when I tried to plot for

voltage versus current when I run my code.

But If I increase the sampling interval, multiple lines occuring at v=1.5 and

v=-1.5 are eliminated.

For eg,

*For t=0:0.00001:10*pi,*

I want to reason behind the occurence of multiple lines for t=0:0.1:10*pi.

Can anyone help me.

Thanks.

I attached my code below:

Code:
clc;
clear all;
close all;
w=1;
M1=2e6;
M2=2e9;
t=0:0.1:10*pi;
M = M2;

for i=1:length(t)

v(i)=2*sin(w*t(i));

if (v(i)>=1.5)
M = M1;

elseif (v(i)<=-1.5)
M = M2;

end

I(i)= v(i)/M;

end

figure(1)
plot(t, v,'r');
hold on;
plot(t, I*1000000,'b');
legend('voltage','current','Location','northeast');
title('Voltage & Current vs time')
grid on;

figure(2)
plot(v, I);
title('Voltage vs Current');
xlabel('Voltage');
ylabel('Current');

Last edited by a moderator:

You're overlaying five cycles, each with with different sample points.

Using more sample points, you still get five curves, but more close together, so they appear as one.

• vetriece86@gmail.com

Points: 2