fzero function not working with symsum
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Walter Roberson
il 7 Feb 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 Commenti
Walter Roberson
il 8 Feb 2022
Modificato: Walter Roberson
il 8 Feb 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])
Vedere anche
Categorie
Scopri di più su Calculus in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

