Using odesolver with functions that have many inputs
조회 수: 3 (최근 30일)
이전 댓글 표시
I'm trying to use ode45 to integrate a first order differential equation. The first line of my function m-file is
function dEds = dPdE(s, E, U0, H0, mu, T, t, initial, final,timestep)
s is my independent variable, and E(s) is what I am solving for. All the other variables are matrices or scalars, and are used in the m-file. My question is, when using ode45, how do I specify these other variables? On this page
other inputs are being put in after the (blank) options, and I verified for myself that it can work, but I haven't seen any documentation refer to that. Furthermore it doesn't seem to be working when I try and solve my equation:
[s E]=ode45(@dPdE,[0 5],E(321),[],U0,H0,mu,5,3.2,2,3,.01);
It says too many input arguments. How can I make this go?
(A more trivial question I have is whether I need to put s as an input argument if the function never uses it.)
댓글 수: 0
채택된 답변
Andrew Newell
2011년 6월 10일
The documentation in the link you provide probably applies to an older version of MATLAB than you have. Instead, create an anonymous function:
f = @(s,E) dPdE(s, E, U0, H0, mu, T, t, initial, final,timestep);
Then you can solve the equation using
[s, E]=ode45(f,[0 5],E(321));
Yes, you do need to provide s as an input argument.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!