1. Use the meshgrid function with the following data: -8: 0.5: 8
  2. Use the following equation: R=x2+y2 treat x and y as vectors
  3. Use the Z=sin RR
  4. Hint: you will need the following: Z(R==0)=1
  5. Use the mesh function for you variables

댓글 수: 10

Rik
Rik 2019년 10월 23일

This is your homework. What have you tried so far?

x=-8:0.5:8;
[x,y] = meshgrid (x);
R=sqrt(x.^2+y.^2)
surf(x,y,R)
Guillaume
Guillaume 2019년 10월 23일
Reusing the same variable name (x) for two different purpose is not a good idea. There's no limitation to the number of variables you can have.
You seem to have done step 1) and 2) and skipped 3) and 4). What's preventing you from doing these (other than them being very unclear as you've written them)?
Briana Pass
Briana Pass 2019년 10월 23일
In which line should I change X? Whenever I code lines 3 and 4 I reinforce error. This is how I coded it. Z= sin®/R Z=(R==0)=1 How do I fix this ?
Cyrus Tirband
Cyrus Tirband 2019년 10월 23일
What is the error you get? Can you format your code using the code blocks in the comments? It looks like you have the right answer, but it's hard to tell because of the awful typesetting. Are you using the pointwise division operator (./) to calculate Z?
Guillaume
Guillaume 2019년 10월 23일
In which line should I change X
Whichever you want, but it makes more sense to keep the output of meshgrid as x, since that's what your assignment use. The first x which serves a completely different purpose could be renamed to gridspacing or something similar.
Briana Pass
Briana Pass 2019년 10월 23일
I included the image I got too. I know it is not right. I do not know where I am making the error.
x=-8:0.5:8;
Y=-8:0:8;
Z=-8:1.5:8;
[x,Y] = meshgrid (-8:0.5:8);
R=sqrt(exp(-x.^2-Y.^2))
surf(x,Y,x.*exp(R))
Z(R==0)=1Screen Shot 2019-10-23 at 9.36.31 AM.png
Cyrus Tirband
Cyrus Tirband 2019년 10월 23일
The assignment is asking you to plot z = sin (R)/R, you're plotting x*exp(R).
If you define Z like was asked, you'll have to account for the location where R = 0 (given the snippet you were given) because matlab will naïvely divide zero by zero and give you NaN or Inf. You can then plot Z with the surf command. You'll get something like thissurf_sinc.png
Guillaume
Guillaume 2019년 10월 23일
matlab will naïvely divide zero by zero and give you NaN or Inf
There is nothing naive about it. dividing zero by zero is mathematically undefined. Matlab will give you NaN (not a number) if you still do it, never Inf for that.
The function is undefined at 0. You can define a new function that is:
which is what seems to be asked here.
Briana Pass
Briana Pass 2019년 10월 23일
I am still very confused. What should my code consist of? If I have a deatiled line by line code I could fix my orignial errors.

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2019년 10월 23일

댓글:

2019년 10월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by