Hello, I've successfully express the Sum Series, but I have a small issue on implementing it surface plot.
I attempt I'm various methods, but always have the error: "Error using surf (line 71): Z must be a matrix, not a scalar or vector."
I would appreciate if anyone can figure out any small modifications on the surf plot.
h=2;
v=2;
l=2;
a = linspace(-5,5,100);
b = linspace(-5,5,100);
[x t]=meshgrid(a,b);
syms x t m
f = (8*h/pi^2)*(((-1)^(m-1))/((2*m-1)^2))*sin(((2*m-1)*pi*v*x)/l)*cos(((2*m-1)*pi*v*t)/l);
sum_f = symsum(f,m,1,Inf);
surf(x,t,sum_f);

 Respuesta aceptada

KSSV
KSSV el 25 de Mzo. de 2022
h=2;
v=2;
l=2;
a = linspace(-5,5,100);
b = linspace(-5,5,100);
[x, t]=meshgrid(a,b);
m = 1000 ;
for i = 1:m
f = (8*h/pi^2)*(((-1)^(m-1))/((2*m-1)^2))*sin(((2*m-1)*pi*v*x)/l).*cos(((2*m-1)*pi*v*t)/l);
end
% sum_f = symsum(f,m,1,Inf);
surf(x,t,f);

3 comentarios

Charles Thomas
Charles Thomas el 25 de Mzo. de 2022
Thank You very much! I really appreciate your help.
KSSV
KSSV el 25 de Mzo. de 2022
Thanks is accepting and/or voting the answer. :)
I think you want to make a few changes to the code if I understand the question correctly.
The loop in the example code repeats the same calculation over and over and doesn't generate the sum. To fix that we can switch m and i. We can also record the results of f for each iteration of m.
Here i is the number of iterations and m is the summation index, and f is now the sum of the result of the equation.
h=2;
v=2;
l=2;
r=100; % resolution of the grid
a = linspace(-5,5,r);
b = linspace(-5,5,r);
[x, t]=meshgrid(a,b);
f=zeros(r);
i = 1000 ; % number of iterations
for m = 1:i
f = f + (8*h/pi^2)*(((-1)^(m-1))/((2*m-1)^2))*sin(((2*m-1)*pi*v*x)/l).*cos(((2*m-1)*pi*v*t)/l);
end
surf(x,t,f);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Productos

Versión

R2021b

Etiquetas

Preguntada:

el 24 de Mzo. de 2022

Comentada:

el 8 de Dic. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by