フィルターのクリア

Nonscalar arrays of function handles are not allowed; use cell arrays instead.

5 ビュー (過去 30 日間)
Tevel Hedi
Tevel Hedi 2022 年 4 月 9 日
編集済み: Torsten 2022 年 4 月 9 日
syms o p
fun1=o+p;
fun2=o*p+5;
eq1=matlabFunction(fun1);
eq2=matlabFunction(fun2);
bbb=fsolve(@(o,p) [eq1;eq2],[0,1]);
What am I doing wrong?

採用された回答

Steven Lord
Steven Lord 2022 年 4 月 9 日
You need to evaluate the function handles in your fsolve call. Alternately you could skip converting the symbolic expressions into function handles and use solve.
syms o p
fun1=o+p;
fun2=o*p+5;
eq1=matlabFunction(fun1);
eq2=matlabFunction(fun2);
bbb=fsolve(@(op) [eq1(op(1), op(2));eq2(op(1), op(2))],[0,1]) % or
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
bbb = 1×2
-2.2361 2.2361
bbb2 = solve(eq1, eq2, o, p)
bbb2 = struct with fields:
o: [2×1 sym] p: [2×1 sym]
vpa(bbb2.o, 5)
ans = 
vpa(bbb2.p, 5)
ans = 

その他の回答 (2 件)

David Hill
David Hill 2022 年 4 月 9 日
Why use symbolic and convert?
fun=@(x)[x(1)+x(2);x(1)*x(2)+5];
x=fsolve(fun,[0,1]);
  1 件のコメント
Tevel Hedi
Tevel Hedi 2022 年 4 月 9 日
i need it to be symbolic in my main code where i use a script of that sort.

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


Torsten
Torsten 2022 年 4 月 9 日
編集済み: Torsten 2022 年 4 月 9 日
syms o p
fun1 = o+p;
fun2 = o*p+5;
fun = [fun1,fun2];
eq = matlabFunction(fun);
bbb = fsolve(@(x)eq(x(1),x(2)),[0,1]);

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by