Clear Filters
Clear Filters

Converting 2 symbolic expressions into a function handle

2 views (last 30 days)
I have to solve 2 symbolic expressions num1 = 0 & num2 = 0.
For this , i have given the code like the following ::
syms p q ;
num1 = 3* p^3 + 4*p*q + 5* p^2 + 1; num2 = 4* p^5 + 9*p^3*q + 2* p*q^2 + 2;
fh = matlabFunction(num1, num2)
[x] = fsolve( fh, [1,2] )
When i execute this code, i am getting the following error .
" ??? Input argument "q" is undefined.
Error in ==>
sym.matlabFunction>makeFhandle/@(p,q)deal (p.*q.*4.0+p.^2.*5.0+p.^3.*3.0+1.0,p.*q.^2.*2.0+p.^3.*q.*9.0+p.^5.*4.0+2.0)
Error in ==> fsolve at 248
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue. "
I tried a lot to rectify this error. But, could not get any thing. Please help me if anyone knows how to solve this problem.
Thanks in advance.
--Kalpana

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 13 Aug 2013
syms p q;
num1 = 3* p^3 + 4*p*q + 5* p^2 + 1;
num2 = 4* p^5 + 9*p^3*q + 2* p*q^2 + 2;
f = matlabFunction([num1;num2],'vars',{[p,q]});
out = fsolve(f,[1,2]);
  1 Comment
kalpana
kalpana on 13 Aug 2013
Thank you very much 'Andrei Bobrov' for your answer. I executed the code which you have given. It is working.
Again, Thanks a lot to you. ---Kalpana

Sign in to comment.

More Answers (0)

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!