How do I solve Time dependent parameter in ODE
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Alan Stevens
on 21 Oct 2020
Edited: Alan Stevens
on 21 Oct 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
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!