Effacer les filtres
Effacer les filtres

What wrong with the code

3 vues (au cours des 30 derniers jours)
kt chua
kt chua le 26 Oct 2021
Commenté : kt chua le 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 .

Réponse acceptée

chris crowley
chris crowley le 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 commentaire
kt chua
kt chua le 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by