Passing Functions and m-files to functions
2 ビュー (過去 30 日間)
古いコメントを表示
Hi Mathworks,
I have an m-file which codes up a system of differential equations;
9D_system
This has various parameters in it, and I have a few parameter schemes for specifying the values to these parameters;
P1.m, P2.m, P3.m
I want to be able to specify which parameter scheme I endow the system with, and then solve this system of differential equations with ode15s.
How do I do this?
Moreover, the parameter schemes
P1.m, P2.m, P3.m
each call functions (some of the parameters are functions of other parameters, and so must be calculated by these called functions). Thus the ode will have a series of nested functions being called!!
Any help on this would be greatly appreciated. :)
Linford
1 件のコメント
採用された回答
Sean de Wolski
2013 年 2 月 12 日
@Linford, these are the ways we recommend passing extra parameters:
e.g:
ode45(@(t,y)myfun(t,y,@p1)
And
function x = myfun(t,y,pfun)
stuff = pfun();
x = do_things_with(stuff,t,y)
1 件のコメント
Jan
2013 年 2 月 12 日
編集済み: Jan
2013 年 2 月 12 日
Or add the parameters as additional arguments to the anoymous function directly. See also: http://www.mathworks.de/matlabcentral/answers/1971
その他の回答 (2 件)
José-Luis
2013 年 2 月 12 日
myStr = 'P1.m'
function [result] = myFun(someArg, myStr)
[str str] = fileparts(myStr);
run(str); %calling your script
%Do your thing
1 件のコメント
参考
カテゴリ
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!