Using ode45 within a for loop
古いコメントを表示
Hi,
So I am trying to use ode45 function when a parameter is changing. I have tried to use a for loop, but MATLAB is displaying some errors, and I do not think I know how to set up the for loop properly.
The parameter I want to vary is c_l
syms c_l
C_n=[ 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 c_l -c_l;
0 0 0 0 0 0 0 0 0 -c_l c_l];
C=zeros(11);
C=C_b+C_n;
Such that I have defined the ode45 function in the following way,
dz=@(t,z,c_l) [ z(12:22);
inv(M)*( k*disp(t)+C(1,1)*vel(t)-[0;0;0;0;0;0;0;0;0;knl*(z(10)-z(11))^3;(-knl)*(z(10)-z(11))^3]-C*z(12:22)-K*z(1:11))];
T=[0 30];
IC=zeros(22,1);
I am aware that the variable c_l does not appear directly in the dz function, but it is in the C_n matrix, is this the problem?
When a specific value of c_l is chosen, the code works fine. However, I would like to plot the function for varying values of c_l, and have tried this method
for c_l = 0:1*10^4:5*10^4;
[t,z] = ode45(dz,T,IC);
figure;
plot(t, z(:,1))
xlabel('t [s]')
ylabel('x [m]')
end
Any suggestions would be greatly appreciated!
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!