How do I reference an undefined variable in an ode45?
Show older comments
Hi, so I've looked around, and I haven't been able to find anything that gives an answer to my question.
Anyway, I'm trying to reference a rate that is a function of time in a ode45 evaluation of a system of differential equations. My actual model is way to long to bother you guys with, so I wrote a very simple version of what I want to do.
Pmax=2;%Sets max of P curve
meantime=12;
omega=meantime/3;
syms t
P=Pmax*10*exp(-((t)-meantime).^2/(2*omega^2))/(omega*sqrt(2*pi));
kwash=.5*P;
%What I want to do:
%xprime=@(t,x)[kwash*x(2);-kwash*x(2)];
%What I have to do:
xprime=@(t,x)[.5*(Pmax*10*exp(-((t)-meantime).^2/(2*omega^2))/(omega*sqrt(2*pi)))*x(2);-.5*(Pmax*10*exp(-((t)-meantime).^2/(2*omega^2))/(omega*sqrt(2*pi)))*x(2)];
x0=[0 100];
tspan=[0:.01:24];
[t,x]=ode45(xprime,tspan,x0);
As you can see, I want reference a time-dependent rate in the transfer equation instead of writing it out within the xprime input. Obviously, I can just write it out here, but my real transfer system is very large and references a number of variables that would be time dependent. As you can see, I treat t like a symbol. My idea was to use matlabFunction to plug it into the xprime, but because xprime is a function itself, that doesn't fly. Also, I need to use an ode of some sort, because my real system cannot be solved using a Dsolve.
Anyway, I hope this makes sense.
Thanks,
John
Answers (0)
Categories
Find more on Programming 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!