How to make a function handle from variable consisting of a function
조회 수: 5 (최근 30일)
이전 댓글 표시
I have a problem like this for example.
x = sym('x',[7,1]);
phi = [ (10001*x2)/800000 - (10001*x1)/400000 + (10001*x3)/600000 - (10001*x4)/1600000 + (10001*x5)/3000000 + (10001*x6*x7)/200000];
% ** This phi was copied from output just so you see how it looks
Is there a way I can make a function handle kind of like this?
phi1 = @(x)phi
(I know this doesn't work but hopefully you get what I am trying to do) Basically I can't explicitly write out the function because it is generated from another algorithm. I don't know the syntax, or if you can even do this.
Also, can someone explain the difference between the operator @ and matlabFunction? Thanks!
댓글 수: 0
채택된 답변
Star Strider
2016년 1월 13일
You can’t get there directly because of the way the Symbolic Math Toolbox creates function calls with matlabFunction:
phi0 = matlabFunction(phi);
phi1 = @(x) phi0(x(1),x(2),x(3),x(4),x(5),x(6),x(7))
A subs call didn’t work, so typing it manually was the only option.
댓글 수: 4
Star Strider
2016년 1월 13일
My approach would be to use the Optimization Toolbox function fsolve to find the roots, assuming I understood the problem well enough to formulate the function to give to it, and if it is possible to do it without the Symbolic Math Toolbox.
The Symbolic Math Toolbox solve function would avoid the necessity of creating an anonymous function, but I doubt it would be faster.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!