Contour not plotting correctly in MATLAB--works in Mathematica
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Emma Reznick
am 19 Mär. 2018
Kommentiert: Abraham Boayue
am 20 Mär. 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 Kommentare
Akzeptierte Antwort
Abraham Boayue
am 20 Mär. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!