Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

I am trying to make a mesh plot with a contour plot beneath it where the decayTime goes from 0.5-10, and time goes from 0 to 15. My formula for the z variable is included below, and I know how to plot, just not where my error is. THANKS!!

1 view (last 30 days)
%%Declarations
phaseShift = 0;
oscillationFreq = 2; % rad/s
decayTime = linspace(.5,10); % seconds
t = linspace(0,15); % seconds
%%Calculations
[xG,yG] = meshgrid(t,decayTime);
z = exp((-1*xG)/yG)*sin((oscillationFreq*xG)+phaseShift);
%%Plotting
meshc(xG,yG,z)
  2 Comments
Stephen23
Stephen23 on 21 Sep 2017
@Snooping Poppet: it is not appreciated when you edit away the text of your question. Imagine if everyone did that, then this entire forum would be useless for anyone else as it would only consist of thousands of threads all reading "This post was taken down". Would you find that useful?
By deleting your question you unilaterally decided that Star Strider's volunteered time helping you shall not be useful to anyone else. Does Star Strider get a say in this decision? Do you think this is why we volunteers come here and write our advice and comments?
If you want a consulting service then you will find plenty of them on them internet. This is a community forum with answers provided by volunteers.

Answers (1)

Star Strider
Star Strider on 29 Nov 2016
Your error is in not doing element-wise operations in your ‘z’ calculation.
This works:
%%Declarations
phaseShift = 0;
oscillationFreq = 2; % rad/s
decayTime = linspace(.5,10); % seconds
t = linspace(0,15); % seconds
%%Calculations
[xG,yG] = meshgrid(t,decayTime);
z = exp((-1*xG)./yG).*sin((oscillationFreq*xG)+phaseShift);
%%Plotting
meshc(xG,yG,z)
grid on
Note the ‘.’ preceding the multiplication and division operators. See the documentation on Array vs. Matrix Operations for details.

This question is closed.

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!