Is this a correct way of 3D graphing an equation with summation
1 次查看(过去 30 天)
显示 更早的评论
x = 0:1:100;
t = 0:1:100;
[X,T] = meshgrid(x,t);
syms n;
u = X + 20 + symsum((20./n.*pi).*(4+5.*-1.^n).*exp(-n^2.*pi.^2.*T./900).*sin(n.*pi.*X./30),n,1,10)
surf(X,T,u)
hold on
grid on
3 个评论
Dyuman Joshi
2024-1-7
I suspect because the original sum has the upper limit of Infinity. And as an example, OP might have chosen to go upto 10 here.
Calculating the numerical "sum" for a larger value of upper limit will be computationally expensive and might be inaccurate, as sum() is unstable.
Torsten
2024-1-7
But you convert the symbolic sum to a function handle and evaluate this function handle. So what is different in your approach from just using "sum" from the very beginning ?
采纳的回答
Dyuman Joshi
2024-1-7
It is better to let the expression be defined as a symbolic expression through-out calculations, then convert it to an anonymous functions and evaluate at last.
Converting to anonymous function and evaluating is much faster compared to evaluating the symbolic function/expression and converting to double.
%Declare symbolic variables
syms n x t
%Define the general term
term = (20/(n*pi)*(4+5*-1^n)*exp(-n^2*pi^2*t/900)*sin(n*pi*x/30));
%Define points
[X,T] = meshgrid(0:100);
%Call symsum(), u will be obtained as a function of x and t
u = 20 + x + symsum(term,n,1,10);
%Convert to anonymous function, specifying the order of variables
u = matlabFunction(u, 'Vars', {x t})
%Evaluate u at X, T
U = u(X, T);
%plot a 3D surface via surf()
surf(X,T,U)
hold on
grid on
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!