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);

 採用された回答

KSSV
KSSV 2022 年 3 月 25 日

1 投票

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 件のコメント

Charles Thomas
Charles Thomas 2022 年 3 月 25 日
Thank You very much! I really appreciate your help.
KSSV
KSSV 2022 年 3 月 25 日
Thanks is accepting and/or voting the answer. :)
Grant Recker
Grant Recker 2022 年 12 月 8 日
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);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 3 月 24 日

コメント済み:

2022 年 12 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by