Effacer les filtres
Effacer les filtres

Contour not plotting correctly in MATLAB--works in Mathematica

6 vues (au cours des 30 derniers jours)
Emma Reznick
Emma Reznick le 19 Mar 2018
Commenté : Abraham Boayue le 20 Mar 2018
I've been trying to get a contour to plot in MATLAB where I have been running analysis on my data, but it will not plot correctly. I have translated the formula into Mathematica (just get rid of all of the matrix '.' operations) and it plots correctly (below).
This is the formula that it should be plotting:
And this is the code I have been running on MATLAB to no avail (it seems to scale with S and F input ranges):
%Establish Constants from Literature
s_u = 1.202^2;
f_u = (168/60)^2;
E0 = 24/60;
%Generate Matricies
f = linspace(0,1);
s = linspace(0,2.5);
[S,F] = meshgrid(s,f);
Z = ((s_u)*(f_u)*E0)./(S.*F.* (s_u-(S.^2)).* (f_u-(F.^2)) );
%Plot
contour(F,S,Z)
Any help would be much appreciated!

Réponse acceptée

Abraham Boayue
Abraham Boayue le 20 Mar 2018
Hey Emma, what happens if you divide by zero, looks like you are doing just that (S and F will become zero at some point in your code). This is not a solution. It's just to allow you see clearly what's going on in the background of your code.
%Generate Matricies (Increase the figure window to see clearly)
f = linspace(-30,20, 30); % some combinations of f and s will include zero
s = linspace(-20,20,30); % in S or F giving an undesirable result, since division
% by zero is not allowed.
[S,F] = meshgrid(s,f);
ss = find(S==0); % Check for zeros in S and F
ff = find(F==0); % Try to make some conditions to avoid dividing by zero.
Z = ((s_u)*(f_u)*E0)./(S.*F.* (s_u-(S.^2)).* (f_u-(F.^2)) );
%Plot
Zmin = min(min(Z));
Zmax = max(max(Z));
spacing = 0.005; % draw more circles between each interval for smaller values
topspace = 1; % increase the upper limit circles
levels=[Zmin:spacing:1,1,1:topspace:Zmax];
contour(F,S,Z,levels);
grid
  2 commentaires
Emma Reznick
Emma Reznick le 20 Mar 2018
That works great, thanks! I had to add a line in to remove the infinite terms, but otherwise very helpful!
Here is what I had to add:
Z(isinf(Z)==1)=15
Abraham Boayue
Abraham Boayue le 20 Mar 2018
You are welcome, I glad you well able to come up with a solution.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by