What wrong with the code

1 view (last 30 days)
kt chua
kt chua on 26 Oct 2021
Commented: kt chua on 27 Oct 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 .

Accepted Answer

chris crowley
chris crowley on 26 Oct 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 Comment
kt chua
kt chua on 27 Oct 2021
Thanks for spoting my mistake. The for loop command indeed cleaner and much easier to perform the function for Odd value of n.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!