How do I solve Time dependent parameter in ODE
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jyoti Yadav
am 21 Okt. 2020
Kommentiert: Jyoti Yadav
am 22 Okt. 2020
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 Kommentare
Akzeptierte Antwort
Alan Stevens
am 21 Okt. 2020
Bearbeitet: Alan Stevens
am 21 Okt. 2020
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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!