Changing Objective Function in fsolve
古いコメントを表示
Hello!
This seems like a simple issue, but I've been unable to spot the solution...
If I have a function with two outputs, let's say something like:
[A,B]=myfun(x,y,z)
I have a situation where I need to be able to solve for either A or B under different circumstances. I know that fsolve automatically takes the objective function as the first entry in the output vector (in this case, A). So I currently have two functions (identical script, except for the order out outputs):
[A,B]=myfun(x,y,z), and [B,A]=myfun(x,y,z)
It would be a lot easier if I could tell my solver which output entry to solve for - is there a way of achieving this?
Many thanks,
Miles
回答 (1 件)
Star Strider
2017 年 8 月 23 日
One approach:
y = shell_fcn(args,opt)
[B,A] = myfun(args(1),args(2),args(3));
switch opt
case 1
y = A;
case 2
y = B;
end
end
Then something like this ...
opt = 1;
x1 = fsolve(@(args) shell_fcn(args, opt), x0);
opt = 2;
x2 = fsolve(@(args) shell_fcn(args, opt), x0);
NOTE — This is UNTESTED CODE. You will probably have to experiment with it.
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!