How to complete this matrix?

  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 Comments

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)
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)?
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 ?
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?
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.
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
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
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.
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.

Sign in to comment.

Answers (0)

Asked:

on 23 Oct 2019

Commented:

on 23 Oct 2019

Community Treasure Hunt

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

Start Hunting!