フィルターのクリア

create vectorfield for an ODE

2 ビュー (過去 30 日間)
Seb
Seb 2011 年 4 月 20 日
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

採用された回答

Jarrod Rivituso
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;
  1 件のコメント
Seb
Seb 2011 年 4 月 20 日
thanks that sounds nice, i will try further on that.
PS: it was the ladder case :)

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by