Filter löschen
Filter löschen

What wrong with the code

3 Ansichten (letzte 30 Tage)
kt chua
kt chua am 26 Okt. 2021
Kommentiert: kt chua am 27 Okt. 2021
I have an assignment question which involve matlab to plot the above graph and below are the code I used.
y=linspace(0,6,10);
x=linspace(0,11,10);
[X,Y]=meshgrid(x,y);
U=(400/pi)*symsum((sin((n*pi*X)/11).*sinh(n*pi*Y/11))/(n*sinh((n*pi*6)/11)),n,1,200);
surf(X,Y,U)
and it return the error"Invalid parameter/value pair arguments"
I'm not sure why it display such error and i check by using simpler function like U=X.*Y, it able to plot the graph, so I cannot identify where the error in my original equation as below.
U=(400/pi)*symsum((sin((n*pi*X)/11).*sinh(n*pi*Y/11))/(n*sinh((n*pi*6)/11)),n,1,200);
but command like plot3(X,Y,U) is working .

Akzeptierte Antwort

chris crowley
chris crowley am 26 Okt. 2021
Your superfluous use of parentheses made it hard to spot, but you have the wrong number of them in your calculation of U. Take a closer look.
Also, you could do this without needing the symbolic toolbox like this:
y=linspace(0,6,10);
x=linspace(0,11,10);
[X,Y]=meshgrid(x,y);
U = zeros(size(X));
for n = 1:2:200
U = U + sin(n*pi*X/11).*sinh(n*pi*Y/11)/ (n*sinh(n*pi*6/11));
end
U = (400/pi)*U;
surf(X,Y,U)
  1 Kommentar
kt chua
kt chua am 27 Okt. 2021
Thanks for spoting my mistake. The for loop command indeed cleaner and much easier to perform the function for Odd value of n.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by