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 个)

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)
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