Solving a system of function handles with fsolve
古いコメントを表示
I have a problem using fsolve in order to solve a system of equations.
a1 to a6 are anonymous functions which are supposed to be equal to 0. T is a vector with six unknown variables T1 to T6. Each anonymous function consists of a term with at least two of those variables.
So with 6 equations and 6 unknowns the solver should be able to solve the system of equations.
I am calling the function like this:
T0 = [0 0 0 0 0 0];
Temp = fsolve(CalcTemps,T0)
function fun = CalcTemps(T)
global a1 a2 a3 a4 a5 a6
fun(1) = a1;
fun(2) = a2;
fun(3) = a3;
fun(4) = a4;
fun(5) = a5;
fun(6) = a6;
end
In my understanding the code is not working as it is not possible to store function handles in fun. I also tried to create fun as a cell array so that the function handles can be stored but then I get an error as fun has to be a function handle and not a cell array.
So my question is: Is it possible to store multiple function handles (a1 to a6) in a single function handle (fun)?
採用された回答
その他の回答 (1 件)
Matt J
2018 年 10 月 23 日
You need to evaluate your function at T,
function fun = CalcTemps(T)
global a1 a2 a3 a4 a5 a6
fun(1) = a1(T);
fun(2) = a2(T);
fun(3) = a3(T);
fun(4) = a4(T);
fun(5) = a5(T);
fun(6) = a6(T);
end
7 件のコメント
Lennart Vogt
2018 年 10 月 23 日
編集済み: Lennart Vogt
2018 年 10 月 23 日
Lennart Vogt
2018 年 10 月 23 日
Ah, sorry. The problem has nothing to do with a1. You have an error in your call to fsolve.
Temp = fsolve(@CalcTemps,T0); % was missing the '@'
Lennart Vogt
2018 年 10 月 23 日
You could define a1 like so
c=v(k);
a1=@(T) c*T;
but I don't think it will make a difference.
Lennart Vogt
2018 年 10 月 24 日
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!