Does anyone know how I might sum and plot the variables I have listed in my code?
Here is my code:
L = 1;
x = 0:L;
psi1 = sqrt(2/L)*sin((pi*x)/L);
psi3 = sqrt(2/L)*sin((pi*x)/L)-sqrt(2/L)*sin((3*pi*x)/L);
psi5 = sqrt(2/L)*sin((pi*x)/L)-sqrt(2/L)*sin((3*pi*x)/L)+sqrt(2/L)*sin((5*pi*x)/L);
psi7 = sqrt(2/L)*sin((pi*x)/L)-sqrt(2/L)*sin((3*pi*x)/L)+sqrt(2/L)*sin((5*pi*x)/L)-sqrt(2/L)*sin((7*pi*x)/L);
A = sum(psi1,psi3,psi5,psi7);
plot ((A),x,0,L)

 採用された回答

Adam Danz
Adam Danz 2020 年 7 月 14 日
編集済み: Adam Danz 2020 年 7 月 14 日

0 投票

A = sum([psi1,psi3,psi5,psi7]); % Result: 1x1
% or
A = sum([psi1;psi3;psi5;psi7]); % Results: 1x2 (length of x)
The square brackets are missing.

5 件のコメント

Matt Forrester
Matt Forrester 2020 年 7 月 14 日
Thank you!
Now when run the code, the plot doesnt have anything in it. Any idea how to get the plot to show.
Adam Danz
Adam Danz 2020 年 7 月 14 日
If you're using the 2nd line in my answer, and if you're using the plot() command in your question, you should see 1 line on the plot.
If you want to see the (0,L) point as well,
plot (A,x,'-',0,L,'o')
Now you'll see the line created by (A,x) and the point at (0,L).
Matt Forrester
Matt Forrester 2020 年 7 月 14 日
Thank You!!!!
Matt Forrester
Matt Forrester 2020 年 7 月 14 日
I also realized that I needed to change my x variable to
x = 0:0.1:L;
Adam Danz
Adam Danz 2020 年 7 月 14 日
I thought that looked fishy. Glad I could help.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by