WHich loops or command should i use in order to plot this equation? It has 3 variables: v,x,t

조회 수: 1 (최근 30일)

답변 (1개)

Mehmed Saad
Mehmed Saad 2020년 4월 15일
편집: Mehmed Saad 2020년 4월 15일
define x,t of same length i.e. select a sampling rate
fs = 10;%Hz
Now define time
t = 0:1/fs:100-1/fs;
x = linspace(0,2*pi,length(t));
i_t = 1.414*sin(w*t+phi);
Now Run the for loop for t
i = 1:length(x)
Now index 1 by 1 and sum them
Remember there are two nested for loop, 1 is for v and other for t
  댓글 수: 2
Parth Patel
Parth Patel 2020년 4월 16일
편집: Parth Patel 2020년 4월 16일
Hi Saad, thankyou very much for the explaination.
My doubt is , dont we need another loop for x as well?
So total 3 - loops:
  1. for x
  2. for t
  3. .for v (harmonics)?
Also in which order should i organise x, t,v in for loop?
Here is the code ,that i tried:
fs = 10;%Hz, sampling frequency
f=60 ; %Hz, supply frequency of current
w=2*pi*f;
t = 0:1/fs:100-1/fs;
x = linspace(0,2*pi,length(t)); % samples of the postion of rotor in radians
phi=0;
i_t = 1.414*sin(w*t+phi);
v=1:2:5; % order of harmoinics to be considered
b=1:length(v); % indexing the elements in v
res= []; % result matrix as an empty matrix
for i =1:length(x)
for b= 1:length(v)
res(b,i)= i_t(i)*cos(v(b)*x); % result variable
end
end
Mehmed Saad
Mehmed Saad 2020년 4월 16일
  1. yes you need another loop for x
  2. you can nest for loop as x t and v or t x and v
  3. You should follow nyquist rate as your frequency is 60Hz so you need atleast 120Hz fs
  4. x size can differ from t, it is not necessary

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by