contour plot real numbers

12 ビュー (過去 30 日間)
Derek Reitnouer
Derek Reitnouer 2019 年 2 月 19 日
コメント済み: Derek Reitnouer 2019 年 2 月 25 日
I wrote a program that just takes an input of x and y values and calculates the principal stresses. It keeps giving me an error about input arguments for contour must be real. All the variables are squared so I am not sure how I would be getting this problem. Thanks.
clc
clear all
% Load
P = 1;
% Length of Beam
L = 1;
% Height of Beam from Neutral Axis
c = 0.1;
x = linspace(0,L);
y = linspace(-c,c);
[X,Y] = meshgrid(x,y);
sigmaP1 = ((3*P/(4*(c^3)))*[X*Y+[((c^2-Y^2)^2)+(X^2)*(Y^2)]^(1/2)]);
contourf(X,Y,sigmaP1,'ShowText','on')

採用された回答

Adam Danz
Adam Danz 2019 年 2 月 19 日
編集済み: Adam Danz 2019 年 2 月 19 日
The values of 'sigmaP1 ' are imaginary. You can identify this just by looking at those values.
sigmaP1 (1:5)
ans =
Columns 1 through 5
1282.8 + 1.9693e-08i 1282.8 + 8.1557e-09i 1282.8 + 2.4166e-08i 1282.8 - 2.1095e-07i 1282.8 - 2.3987e-08i
Or by using isreal()
isreal(sigmaP1)
ans =
logical
0 %which means that your data contains at least 1 imaginary number
In fact, none of the elements of sigmaP1 are real numbers as confirmed by
any(imag(sigmaP1(:))==0)
ans =
logical
0 %no real numbers found
  12 件のコメント
Adam Danz
Adam Danz 2019 年 2 月 21 日
This is telling. Since my break-down produces the same exact results as the full equation, that confirms that the break-down is correct. But since the break-down results to not match your expected results, that tells us that the original equation is wrong (or your expected results are wrong).
I think it's a great idea to reduce the number of inputs to ~5 so you can manage the comparison. I haven't read through your code above and I didn't see a specific follow-up question but if you get stuck in this trouble-shooting process, let me know.
Derek Reitnouer
Derek Reitnouer 2019 年 2 月 25 日
Thats correct, the breakdown does match the full equation. Maybe I'm not understanding the way meshgrid works. If I go down to 3 variables, the big X equals a 3x3 matrix consisting of 0, 0.5, 1. The big Y is the same with variables -0.1,00.1. The output for sigmP1(1,1) should be calculated using the values X=0 and Y = -0.1. The equation you wrote down is the correct equations and it should return 0, not 75.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by