Nonscalar arrays of function handles are not allowed; use cell arrays instead.
조회 수: 5 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
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
bbb2 = solve(eq1, eq2, o, p)
vpa(bbb2.o, 5)
vpa(bbb2.p, 5)
댓글 수: 0
추가 답변 (2개)
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]);
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!