fzero function not working with symsum
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponses (1)
Walter Roberson
le 7 Fév 2022
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
Walter Roberson
le 8 Fév 2022
Modifié(e) : Walter Roberson
le 8 Fév 2022
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)
fun = -u + y-2/pi*s
Fun = matlabFunction(fun, 'vars', x)
FunW = @(x) double(Fun(x))
location = fzero(FunW, [.09 .1])
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

