Looping of more than one first order equations in in function file that can be updated for different value variable parameter

1 回表示 (過去 30 日間)
I want to feed component of vector C (1by20) one by for each loop of system first orde differential equation in order to numerically integrating the whole (320by1) equations simultaneously. i am not able to loop it currectly kindly help me.
function [f]=Loop_stiffness_nonlin12(t,y,C,w,phia,phid,E1,lmda1,m0,e,N)
%% sinusoidal force
% W=2*N*pi/60;
%
% p1=m0*e*(W)^2*sin(W*t);
%
% p1=p1/10;
f= zeros(320,1);
for j=1:16:305
f(j)=y(1+j);
f(1+j)= -w(1)^2*y(j)-lmda1*y(1+j)-C(1,i)*phid(1)*(phid(1)*y(j)-y(2+j))^3;
f(4+j)=y(5+j);
f(5+j)= -w(2)^2*y(4+j)-lmda1*y(5+j)-C(1,i)*phid(2)*((phid(1)*y(j)+phid(2)*y(4+j))-y(2+j))^3;
f(6+j)=y(7+j);
f(7+j)= -w(3)^2*y(6+j)-lmda1*y(7+j)-C(1,i)*phid(3)*((phid(1)*y(j)+phid(2)*y(4+j);
f(8+j)=y(9+j);
f(9+j)= -w(4)^2*y(8+j)-lmda1*y(9+j)-C(1,i)*phid(4)*((phid(1)*y(j);
f(10+j)=y(11+j);
f(11+j)= -w(5)^2*y(10+j)-lmda1*y(11+j)-C(1,i)*phid(5)*((phid(1)*y(j)+phid(2)*y(4+j));
f(2+j)= y(3+j);
f(3+j)= (C(1,i)/E1)*((phid(1)*y(j)+phid(2)*y(4+j)+phid(3)*y(6+j)+phid(4)*y(8+j)+phid(5)*y(10+j))-y(2+j))^3+(lmda1/E1)*((phid(1)*y(1+j)+phid(2)*y(5+j)
end
end
end

採用された回答

darova
darova 2021 年 4 月 6 日
See this example
f = @(t,x,a) [x(2); x(1)-a*sin(x(1))];
a = rand(10,1); % parameter
cmap = jet(10);
for i = 1:length(a)
[t,x] = ode45(f,[0 2],[1 1],[],a(i));
line(t,x(:,1),'color',cmap(i,:))
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by