Contour not plotting correctly in MATLAB--works in Mathematica
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/171390/image.jpeg)
This is the formula that it should be plotting:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/171391/image.jpeg)
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!
0 commentaires
Réponse acceptée
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!