How to add two loops for two variables in a nonlinear ode
2 views (last 30 days)
Show older comments
For a nonlinear ode:
dy/dt=a*(1-10^(b*y))
How to solve this ode (i.e y) for different conditions, for example:
a=0:1:10 and b=0:1:10 at t=10?
0 Comments
Answers (2)
Marc
on 23 Jun 2016
See nested functions...
Basically you need to define a function that takes a and b as inputs, solves the ode with one of the ode solvers with the function nested. Anything outside the nested function, a and b are 'known' to the nested function.
function [yout, tout]= odeIn(a, b)
t = your time interval
Define your initial cond
yout = ode15s(yournestedfunc, t, initial cond)
function dydt = yournestedfunc(t)
your function with a and b
end
end
Something like that... Or you can turn your function into an anonymous function that calls a and b as variables. There is a good section in the help documentation on this...
Roger Stafford
on 23 Jun 2016
This particular equation can be solved by ordinary calculus methods. It has the three possible analytic forms:
1) For y > 0, y = 1/(b*log(10))*log(1/(1-exp(-c*(t+K))))
2) y = 0, a constant in time
3) For y < 0, y = 1/(b*log(10))*log(1/(1+exp(-c*(t+K))))
where c = a*b*log(10) and where K is selected to satisfy whatever initial condition you apply to y.
You can derive these solutions by making the substitution
z = 10^(b*y)
and the resulting differential equation in z can readily be solved:
1/(z*(1-z))*dz/dt = a*b*log(10)
Evaluating the above expressions directly is presumably easier than making use of the numerical ‘ode’ functions in matlab (once you are convinced they are correct.)
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!