How do I solve Time dependent parameter in ODE
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello, I am facing problem in solving time dependent parameter in ODE solver. In my dydt fuction, I want G parameter to change as t changes in dydt equation. How can i give input of G parameter in dydt equation. I have tried the below code but it shows error.
[t, ymodel] = ode45(@DiffEqs_crytallization, myODE, tspan, y0, options)
where myODE: (G is of the same matrix size as t and I want to use G in my main function @DiffEqs_crystallization))
function [G] = myODE(t, S)
S=[1.0032; 1.1425; 1.323; 1.53; 1.28; 1.22; 1.09; 1.08];
Kg=exp(3.82);
g=1.62;
G=Kg.*((S-1).^g);
function [dydt] = DiffEqs_crytallization(t,y)
for i= 1:N
for j=2:N
extravector1=extravector1+ (y(i)./xmd(j));
end
%dydt(i)=(G./delx(i))*(0-0.5*(y(i+1)+y(i)))+k*(xmd(i+1)-xmd(i))*extravector1;
end
dydt=dydt';
return;
댓글 수: 2
채택된 답변
Alan Stevens
2020년 10월 21일
편집: Alan Stevens
2020년 10월 21일
Perhaps your code needs to be structured more along the following lines;
tspan = .....
y0 = .....
options = .....
[t, ymodel] = ode45(@myODE, tspan, y0, options);
function dydt = myODE(t, y)
S=[1.0032; 1.1425; 1.323; 1.53; 1.28; 1.22; 1.09; 1.08];
Kg=exp(3.82);
g=1.62;
G=Kg.*((S-1).^g); % If G is a function of t then express that here
delx = ... % Needs to be defined
xmd = .... % Ditto
k = ... % Ditto
extravector1 = ...% Needs to be initialised
for i= 1:N
for j=2:N
extravector1=extravector1+ (y(i)./xmd(j));
end
dydt(i)=(G./delx(i))*(0-0.5*(y(i+1)+y(i)))+k*(xmd(i+1)-xmd(i))*extravector1;
end
dydt=dydt';
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!