I'd like to plot 'mesh' for both f and g functions in MATLAB.
I'd tried this for f and g:
clc
clear
close all
%%plot f
[x,y] = meshgrid(linspace(-pi,pi,50));
f=x.*y ;
subplot(1,2,1)
mesh(f)
title('f')
%%plot g
A=4*(-1)^(m+n)*(sin(m.*x)*sin(n.*y))/(m*n);
g=sum(sum(A,n,1,inf),m,1,inf);
subplot(1,2,2)
mesh(g)
title('g')
The result is:
I don't have any idea to plot g directly from its' function, any help would be appreciated.

 채택된 답변

Amin Ghasemi
Amin Ghasemi 2016년 11월 11일

0 개 추천

finally I found the solution, thanks all.
clc
clear
close all
%%plot f
[x,y] = meshgrid(linspace(-pi,pi,40));
f=x.*y ;
subplot(1,2,1)
mesh(f)
title('f(x,y)=xy')
%%plot g
syms m n X Y
assume(m>=1);
assume(n>=1);
assume(X>-pi & X<pi);
assume(Y>-pi & Y<pi);
A = 4*(-1)^(m+n)*(sin(m*X)*sin(n*Y))/(m*n);
g = real(double(subs(symsum(symsum(A,n,1,Inf),m,1,Inf),{X,Y},{x,y})));
subplot(1,2,2)
mesh(g)
title('g: Double Fourier series of f for -\pi to \pi ')

추가 답변 (1개)

Daniel kiracofe
Daniel kiracofe 2016년 11월 11일

0 개 추천

I think your problem is this line
A=4*(-1)^(m+n)*(sin(m.*x)*sin(n.*y))/(m*n);
from the way you have written it, it looks like you are expecting matlab to treat 'm' and 'n' as symbols here, for later evaluation in the sum command. But by default, matlab does not do symbolic computation. it does numeric computation. it is expecting m and n to be numbers (or vectors, or matrices). I think what you wanted to do was to first declare m and n to be symbols (i.e "syms n m"), and then use symsum() instead of sum(). Look up the documentation for the symbolic math toolbox for more information.

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

질문:

2016년 11월 10일

답변:

2016년 11월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by