create vectorfield for an ODE
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello everyone, my problem is the following:
consider the differential equation x' = f(x), where f is a vector function. consider that for my problem, i have a formula to create f. given a vector a of appropriate size, f( x ) = a* (a_transpose*x). Now i want to test this differential equation with variation of a. Instead of writing f by hand, i want to have one function that has the vector a as an input and gives me the function handle of the right hand side of the ode.
But i came a cross a hard problem: you cant change a handle once its done. also, i cant write the right hand side first and declare the anonymous function because one cant just write x(1), x(2) ...
is there a easy way to figure this out?
thanks a lot
댓글 수: 0
채택된 답변
Jarrod Rivituso
2011년 4월 20일
Are you looking to have "a" change within a single call to ODE45, or would you like it to change on each subsequent call?
If the latter is the case, you could use an anonymous function wrapper to the derivative function
function dy = derivs(t,y,a)
dy = a*y;
And then
>> derivWrapper = @(t,y) derivs(t,y,5);
>> [t,y] = ode45(derivWrapper,[0 10],2)
>> plot(t,y)
If the former is the case, you could modify your derivative function to change "a" as you want to.
function dy = derivs(t,y)
if (t > 5)
a = 1;
else
a = 3;
end
dy = a*y;
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!