How to add two loops for two variables in a nonlinear ode

1 回表示 (過去 30 日間)
Long Cheng
Long Cheng 2016 年 6 月 23 日
コメント済み: Long Cheng 2016 年 6 月 23 日
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?

回答 (2 件)

Marc
Marc 2016 年 6 月 23 日
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...
  1 件のコメント
Long Cheng
Long Cheng 2016 年 6 月 23 日
Thank you! Let me give a try :)

サインインしてコメントする。


Roger Stafford
Roger Stafford 2016 年 6 月 23 日
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.)
  1 件のコメント
Long Cheng
Long Cheng 2016 年 6 月 23 日
That's great idea! Thanks a lot!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by