WHAT TO GRAPH USING ELEMENTWISE MULTIPLCATION

조회 수: 1 (최근 30일)
YOGESHWARI PATEL
YOGESHWARI PATEL 2017년 6월 5일
댓글: YOGESHWARI PATEL 2017년 6월 5일
i WANT TO PLOT THE GRAPH FOR
U(X,T)=EXP(-4*PI^2*0.5*y)*SIN(2*PI*x)
AS PER THE SUGGESTION GIVEN ON MATHWORK I WROTE THIS CODE BUT STILL GRAPH IS NOT CORRECT. i AM USING R2013 VERSION OF MATLAB. pROVIDE SOME MORE EXAMPLE.
x = linspace(0,1 ,51)';
y = linspace(0,1,51)';
[X, Y] = meshgrid(x, y);
Z=exp(-4.*(pi^2)*0.5*Y)*sin(2*pi*X);
surf(X, Y, Z);
ylabel('t');
xlabel('x');
zlabel('u(x,t)')
  댓글 수: 3
YOGESHWARI PATEL
YOGESHWARI PATEL 2017년 6월 5일
Sorry I was not shouting first time i came to know that use capital letters that means shouting.Sorry .
YOGESHWARI PATEL
YOGESHWARI PATEL 2017년 6월 5일
Thank for making concept clear.

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2017년 6월 5일
편집: Stephen23 2017년 6월 5일
It works perfectly for me, exactly like I showed you before, (but you ignored):
x = linspace(0,1 ,51)';
y = linspace(0,1,51)';
[X,Y] = meshgrid(x, y);
Z = exp(-2*pi^2*Y).*sin(2*pi*X); % I only changed this line!
surf(X, Y, Z);
ylabel('t');
xlabel('x');
zlabel('u(x,t)')
Lets have a look, so you can understand why that line. You wrote this:
Z=exp(-4.*(pi^2)*0.5*Y)*sin(2*pi*X);
^ element-wise multiply, but pointless.
But what is the point of element-wise multiplication with 4? 4 is a scalar number and so is pi, it serves no purpose whatsoever to use element-wise multiplication with them. So what parts of that calculation are not scalar? Answer: X and Y. Therefore any operation involving X and Y, or any other arrays derived from them will need to use element-wise operations. In this case this means the exp(..) and sin(..) terms will need to be multiplied using element-wise multiply. And thus I showed you (twice so far) this, which uses element-wise multiply for the terms that are arrays (and I did not use it on the scalar values like you did):
exp(-2*pi^2*Y).*sin(2*pi*X)
^ element-wise multiply, required.
or if you really want to have that 4 and 0.5:
exp(-4*pi^2*0.5*Y).*sin(2*pi*X)
You have now been told this multiple times:
  댓글 수: 2
YOGESHWARI PATEL
YOGESHWARI PATEL 2017년 6월 5일
Sir But X is matrix so it should be element wise multiplication for 2*pi^2*X
Stephen23
Stephen23 2017년 6월 5일
편집: Stephen23 2017년 6월 5일
@YOGESHWARI PATEL: no, 2*pi^2*X does not need element-wise multiplication. It is optional in that set of operations. In my answer I also explained that it is not required for the operations that you used that include only scalars and one array. You could use it there, but it does not need it (there is no harm in using either, it is up to you). In my answer I showed you working code that does not use it. Did you not notice that my code was working (it included a nice colorful figure: did you see it?)
Did you actually read my answer?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by