Contour not plotting correctly in MATLAB--works in Mathematica

3 ビュー (過去 30 日間)
Emma Reznick
Emma Reznick 2018 年 3 月 19 日
コメント済み: Abraham Boayue 2018 年 3 月 20 日
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!

採用された回答

Abraham Boayue
Abraham Boayue 2018 年 3 月 20 日
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 件のコメント
Emma Reznick
Emma Reznick 2018 年 3 月 20 日
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 2018 年 3 月 20 日
You are welcome, I glad you well able to come up with a solution.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by