Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

help with matlab syntax

rjrrjr Posts: 1Member
hey guys im having trouble with some syntax, i know what i need the program to do but im not sure the syntax. I need the line in the for loop where it says Omega=??; I want to set Omega equal to the 'k-th' component of OMEGA, but I am not sure what is the syntax for that. Any help would be appreciated. Here is the script:
[code]function lab10ex2
omega = 2; c = 1;
OMEGA = 0:.1:3; A = zeros(size(OMEGA));
t0 = 0; y0 = 0; v0 = 0; Y0 = [y0;v0]; tf = 50; t1 = 25;
for k = 1:length(OMEGA)
Omega = ??;
param = [omega,c,Omega];
[t,Y] = ode45(@f,[t0,tf],Y0,[],param);
i = find(t>t1);
A(k) = (max(Y(i,1))-min(Y(i,1)))/2;
end
Atheory = 1/sqrt((omega^2-Omega^2)^2+(c*Omega)^2);
figure(1)
plot(t,y,'b-'); ylabel('y'); grid on;
xlabel('Omega'); ylabel('A');
%---------------------------------------------------------
function dYdt = f(t,Y,param)
y = Y(1); v = Y(2);
omega = param(1); c = param(2); Omega = param(3);
dYdt = [ v ; sin(Omega*t)-omega^2*y-c*v ];


[/code]






Thanks in advance.

Comments

  • chs773chs773 Posts: 5Member
    Hey,

    I think this is what you are looking for it acceses the element in OMEGA at the current index of the for loop here.

    [code]
    for k = 1:length(OMEGA)
    Omega = OMEGA(k);
    param = [omega,c,Omega];
    [t,Y] = ode45(@f,[t0,tf],Y0,[],param);
    i = find(t>t1);
    A(k) = (max(Y(i,1))-min(Y(i,1)))/2;
    end
    [/code]

    Hope this helped.
Sign In or Register to comment.