MATLAB: How to use fsolve to solve this equation

fsolvefunction

Hi, I am new to Matlab. I tried to solve the equation with respect to x by
function [aaa]=aa(x) syms t aaa=int(3*t,t,0,x)-2;
fsolve('aa',1)
But it turned out: ??? Undefined function or method 'norm' for input arguments of type 'sym'.
Error in ==> trustnleqn at 126 normgradinf = norm(grad,inf);
Error in ==> fsolve at 378 [x,FVAL,JACOB,EXITFLAG,OUTPUT,msgData]=…
Could anyone help me fix the problem ? And why can not I use fsolve in this case ?
Thanks in advance.

Best Answer

One problem is that you need to add ‘x’ to your syms statement. Also, in your call to fsolve, do not use quotes ('') around the name of the function you are using.
I am not certain what you are doing, but I did not have any problems using this code:
syms t x
aaa=int(3*t,t,0,x)-2
aa = matlabFunction(aaa)
produced:
aaa =
(3*x^2)/2 - 2
Using matlabFunction to create an anonymous function out of it,
aa = @(x) (3.*x.^2)./2-2
aa1 = fsolve(aa,1)
Produced:
aa1 =
1.1547e+000
Or, if you want to do everything symbolically,
aa2s = solve(aaa == 0, x)
aa2d = double(aa2s)
produces:
aa2s =
(2*3^(1/2))/3
-(2*3^(1/2))/3
aa2d =
1.1547e+000
-1.1547e+000