fzero function not working with symsum

clear all
clc
close all
y = 0.5;
u = 0.25;
syms n t
fun = @(t) (-u + y-2/pi*symsum(1/n*sin(n*pi*(1-y))*exp(-(n*pi)^2*t),n,1,inf));
fzero(fun,0)
I want to find the root of the following (variable: t). I get the following error message:
Error using num2str (line 47)
Input to num2str must be numeric.
Error in fzero>errHandler (line 581)
sprintf('%g',y),num2str(fy)));
Error in fzero (line 346)
[b,fval,exitflag,output] = errHandler(a,fa,intervaliter,iter,fcount,trace,buildOutputStruct);
Error in a4_1 (line 9)
fzero(fun,0)
What can I do different?

Réponses (1)

Walter Roberson
Walter Roberson le 7 Fév 2022

0 votes

Your symsum() is returning a symbolic value, so your fun() is returning a symbolic value -- but fzero requires the function to return single or double.
You should double() the results of the symsum.

2 commentaires

clear all
clc
close all
y = 0.5;
u = 0.25;
syms n x
s = double(symsum(1/n*sin(n*pi*(1-y))*exp(-(n*pi)^2*x),n,1,inf));
fun = -u + y-2/pi*s;
fzero(fun,0)
Now i get this error message:
Error using symengine
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to substitute values for variables.
Error in sym/double (line 702)
Xstr = mupadmex('symobj::double', S.s, 0);
Error in a4_1 (line 8)
s = double(symsum(1/n*sin(n*pi*(1-y))*exp(-(n*pi)^2*x),n,1,inf));
format long g
y = 0.5;
u = 0.25;
syms n x
s = symsum(1/n*sin(n*pi*(1-y))*exp(-(n*pi)^2*x),n,1,inf)
s = 
fun = -u + y-2/pi*s
fun = 
Fun = matlabFunction(fun, 'vars', x)
Fun = function_handle with value:
@(x)feval(@(n)symsum((exp(-n.^2.*x.*pi.^2).*sin((n.*pi)./2.0))./n,n,1.0,Inf),sym('n')).*(-6.366197723675814e-1)+1.0./4.0
FunW = @(x) double(Fun(x))
FunW = function_handle with value:
@(x)double(Fun(x))
location = fzero(FunW, [.09 .1])
location =
0.0946869595678489

Connectez-vous pour commenter.

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by