MATLAB Answers

Summing multiple variables and plotting them.

28 views (last 30 days)
Matt Forrester
Matt Forrester on 14 Jul 2020 at 20:06
Commented: Adam Danz on 14 Jul 2020 at 21:43
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)

  0 Comments

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 14 Jul 2020 at 20:21
Edited: Adam Danz on 14 Jul 2020 at 20:23
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 Comments

Show 2 older comments
Matt Forrester
Matt Forrester on 14 Jul 2020 at 21:39
I also realized that I needed to change my x variable to
x = 0:0.1:L;
Adam Danz
Adam Danz on 14 Jul 2020 at 21:43
I thought that looked fishy. Glad I could help.

Sign in to comment.

More Answers (0)

Tags