Help with nested for loop, for a matlab hw problem

So i've been working on this problem for a while and not really sure what i'm doing, can someone point me in the right direction
this is my code so far
clc
clear all
t=linspace(0,10,500);
omaga_d_1=.5;
omaga_d_2=1.1;
omaga_d_3=1.5;
sigma_d=3.5;
sigma_d_1=5;
for i=1:t;
c=5*exp.^(-omaga_d_1*t).*cos(sigma_d*t);
end
plot(t,c)

답변 (2개)

KSSV
KSSV 2016년 10월 18일
clc; clear all ;
t=linspace(0,10,500);
omaga_d=[.5 1.1 1.5 3.5];
sigma_d=5;
c = zeros(length(omaga_d),length(t)) ;
for i = 1:length(omaga_d)
c(i,:)=5*exp(-omaga_d(i)*t).*cos(sigma_d*t);
end
plot(t,c)
Adam
Adam 2016년 10월 18일
편집: Adam 2016년 10월 18일
sigma_d = [0.5 1.1 1.5];
omega_d = [3.5 5.0];
Put those into arrays to start with (you got them the wrong way round too so far as I can see). Those are then the two arrays you are expected to loop over in your nested for loops.
I'm not going to do the whole question for you because it is homework but that is a step in the right direction.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2016년 10월 18일

편집:

2016년 10월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by