Plotting an infinite series with multiple variables.

9 ビュー (過去 30 日間)
Tristen Hernandez
Tristen Hernandez 2020 年 2 月 17 日
コメント済み: Rik 2022 年 1 月 26 日
Hi, recently I solved PDE of a 1D wave equation and came to the solution of:
my question while vague,also comes from a place of genuine interest. How exactly would I plot this? I tried splitting it into various components and then summing those components into one function but it just plotted lines for me which leads me here. Any and all help is appreciated; I'm rather novice at this program so detailed explaninations are very welcomed in reference to why you chose particular path way to achieving something.
quick chicken scratch code:
%variables
x=(0:.2:1);
t=(0:.2:1);
n=(0:.4:2);
A = 0.02.*(-1.*(((2.*(n.^2)-5).*sin(n.*pi))/((n.^4)-5.*(n.^2)+4)));
B = 0.02.*(sin(n.*pi.*x).^2);
C = 0.02.*(cos(n.*pi.*t));
u = A.*B.*C;
fplot(u);
  1 件のコメント
David Hill
David Hill 2020 年 2 月 18 日
You could try something like:
[x,t]=meshgrid(0:.2:1,0:.2:1);
u=zeros(size(x));
for n=3:100
u=u-.02*(2*n^2-5)*sin(n*pi)/(n^4-5*n^2+4)*sin(n*pi*x).*cos(n*pi*t);
end
surf(x,t,u);
Your equation does not make much sense to me, since for n=1 and n=2 you are dividing by zero. How can n=0:.4:2 based on your equation?

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

採用された回答

Raunak Gupta
Raunak Gupta 2020 年 2 月 21 日
Hi,
David’s comment above provides a solution but has some missing terms. You may follow the bottom code for doing the same. Also as mentioned in comment n=1 and n=2, the value of u will be undefined so the summation should start at n=3. For the range of x and t you can change them in meshgrid below as per required.
% x and t ranges
xRange = 0:0.02:1;
tRange = 0:0.02:1;
[x,t] = meshgrid(xRange,tRange);
u = zeros(size(x));
for n=3:100
u = u - (0.02*(2*n^2-5)*sin(n*pi)/(n^4-5*n^2+4))*(sin(n*pi*x)^2).*cos(n*pi*t);
end
surf(x,t,u);
  2 件のコメント
Tristen Hernandez
Tristen Hernandez 2020 年 2 月 24 日
This visualized it perfectly thank you so much! I appreciate the help and also thanks for poiinting out the error in my original equation,that was giving a lot of headache and I just overlooked it.
Rik
Rik 2022 年 1 月 26 日
Comment posted as flag by Gabriel Zev Betancourt Pinto:
It was really helpful Thank you so much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBoundary Conditions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by