Hi, I have the following three equations:
a = Q/k*(N1+ N2);
b = Q/k*(N1 + N2);
dQ/dt = r - k*(N1*a + N2*b);
where, r, k, N1, and N2 are parameters. I am a newbie to Matlab. I know I should use ode45 to solve for Q and provide an initial value. But, I could not quite figure out how to use values of Q to calculate a and b. Can anyone please help? Thank you. -Sam

 Akzeptierte Antwort

James Tursa
James Tursa am 12 Jun. 2018

0 Stimmen

1) Look at the examples here:
2) Write your derivative function. E.g., it will look something like this:
function dQdt = Qdot(t,Q,r,k,N1,N2)
a = etc <-- you fill in the rhs
b = etc <-- you fill in the rhs
dQdt = etc <-- you fill in the rhs
end
3) You write code to call ode45. E.g., an outline
r = etc
k = etc
N1 = etc
N2 = etc
Q0 = etc <-- the initial condition
tspan = etc <-- the time span
[t,Q] = ode45(@(t,Q) Qdot(t,Q,r,k,N1,N2), tspan, Q0);
Then plot the results, or whatever the assignment calls for.

2 Kommentare

Sam K
Sam K am 12 Jun. 2018
Thank you James. That worked for me. I have a quick follow-up question. I figured out how to plot Q. But, I need to plot a and b as well. How can I do that? Thank you.
Since a and b are functions of everything you have in your workspace, simply calculate them directly after you call ode45:
a = Q/k*(N1 + N2);
b = Q/k*(N1 + N2);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Gefragt:

am 12 Jun. 2018

Kommentiert:

am 12 Jun. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by