現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
where is the error in my code?
1 回表示 (過去 30 日間)
古いコメントを表示
Hi every one,
when I run the following code, I get a plot with unexpected two lines as circled by the red lines in the image attached! where is the error because we do not expect these lines to appear according to the physical equations?
V1 = @(r,w) -acosh(10*(w/(1600*r + 21))^(1/2))/20000000000
V2 = @(r,w) acosh(10*(w/(1600*r + 21))^(1/2))/20000000000
% Define function to be integrated
fun = @(x,r,w)0.0018./((w./((cosh(10^10.*x./0.5)).^2)-(r.*16+0.21)).^(1/2));
www = @(w,r)5.124-6.4*10^-6.*(exp(-215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2))).*log10((exp(-215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2)))))./(r.*(integral(@(x)fun(x,r,w),V1(r,w),V2(r,w)))))-(exp(-37.45.*r).*(70.31));
fimplicit(www,[0 5 0 0.075],'MeshDensity',500, 'LineWidth',1.5),grid
15 件のコメント
Torsten
2022 年 6 月 19 日
I suggest you make a surface plot of www in the region of interest to see what happens.
help surf
Abdallah Qaswal
2022 年 6 月 20 日
May you please help me plot the code with surf? because I tried using surf but I got an error, see here please:
V1 = @(r,w) -acosh(10*(w./(1600*r + 21))^(1/2))/20000000000
V2 = @(r,w) acosh(10*(w./(1600*r + 21))^(1/2))/20000000000
% Define function to be integrated
fun = @(x,r,w)0.0018./((w./((cosh(10^10.*x./0.5)).^2)-(r.*16+0.21)).^(1/2));
www = @(w,r)5.124-6.4*10^-6.*(exp(-215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2))).log10(exp(-215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2))))/(r.*(integral(@(x)fun(x,r,w),V1(r,w),V2(r,w)))))-(exp(-37.45.*r).*(70.31));
surf(www,[0 5 0 0.075],'MeshDensity',500, 'LineWidth',1.5),grid
Abdallah Qaswal
2022 年 6 月 20 日
when I delete the log part (log10(exp(-215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2)))), the straight linear line on the left is removed, so I think the problem is in writing the common logarithm, right?
Also, the horizontal line was removed when I change the range of R values from [0 0.075] to [0.01 0.075] so I removed the 0 to avoid infinity.
But the line that is remained is the left linear line! any idea to remove it?
Torsten
2022 年 6 月 20 日
The part of your formula
...^(1/2))).log10(...
is incorrect. There must be a * or / before the log10.
w = 0:0.05:5;
r = 0.001:0.001:0.075;
[W,R]=meshgrid(w,r);
www = @(w,r)5.124-6.4*10^-6.*(exp(-215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2))).log10(exp(-215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2))))/(r.*(integral(@(x)fun(x,r,w),V1(r,w),V2(r,w)))))-(exp(-37.45.*r).*(70.31));
surf(W,R,www(W,R))
Dot indexing is not supported for variables of this type.
Error in solution (line 4)
www = @(w,r)5.124-6.4*10^-6.*(exp(-215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2))).log10(exp(-215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2))))/(r.*(integral(@(x)fun(x,r,w),V1(r,w),V2(r,w)))))-(exp(-37.45.*r).*(70.31));
Abdallah Qaswal
2022 年 6 月 20 日
編集済み: Torsten
2022 年 6 月 20 日
I edited the code according to your suggestions but unfortunately, the code still in error:
w = 0:0.05:5;
r = 0.001:0.001:0.075;
[W,R]=meshgrid(w,r);
V1 = @(r,w) -acosh(10*(w./(1600*r + 21)).^(1/2))/20000000000;
V2 = @(r,w) acosh(10*(w./(1600*r + 21)).^(1/2))/20000000000;
% Define function to be integrated
fun = @(x,r,w)0.0018./((w./((cosh(10^10.*x./0.5)).^2)-(r.*16+0.21)).^(1/2));
www = @(w,r)5.124-6.4*10^-6.*(exp(-215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2))).*log10(exp(-215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2))))./(r.*(arrayfun(@(r,w)integral(@(x)fun(x,r,w),V1(r,w),V2(r,w)),R,W))))-(exp(-37.45.*r).*(70.31));
surf(W,R,www(W,R))
Warning: Inf or NaN value encountered.
Torsten
2022 年 6 月 20 日
See the modified code from above.
You will have to check where and why the Inf and NaN values in the surface plotting appear.
I suggest you make a matrix M and inspect it:
w = 0:0.05:5;
r = 0.001:0.001:0.075;
[W,R]=meshgrid(w,r);
V1 = @(r,w) -acosh(10*(w./(1600*r + 21)).^(1/2))/20000000000;
V2 = @(r,w) acosh(10*(w./(1600*r + 21)).^(1/2))/20000000000;
% Define function to be integrated
fun = @(x,r,w)0.0018./((w./((cosh(10^10.*x./0.5)).^2)-(r.*16+0.21)).^(1/2));
www = @(w,r)5.124-6.4*10^-6.*(exp(-215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2))).*log10(exp(-215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2))))./(r.*(arrayfun(@(r,w)integral(@(x)fun(x,r,w),V1(r,w),V2(r,w)),R,W))))-(exp(-37.45.*r).*(70.31));
WWW = www(W,R);
Warning: Inf or NaN value encountered.
M(:,:,1) = W;
M(:,:,2) = R;
M(:,:,3) = WWW;
M(:,:,3)
ans = 75×101
1.0e+65 *
-0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000
-0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000
-0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000
-0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000
-0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000
-0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000
-0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000
-0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000
-0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000
-0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000
Abdallah Qaswal
2022 年 6 月 20 日
Thnak you! but this did not solve the original question because I would like to plot the relationship between R and W only without www, which is not a physical parameter in my case here!
As I told you, the issue is with the log part in the equation, any idea?
Abdallah Qaswal
2022 年 6 月 20 日
Honestly, I do not understand the approach you suggested but what I noticed is that substituting the values on the undesired line on the left yields undefined values in the common logarithm like 0 or negative value, is there any function to exclude such undefined values?
Abdallah Qaswal
2022 年 6 月 20 日
yes, the nonsens is (log of an exponential value), this one : log10(exp(-215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2)))) because once I remove it ( which does not affect the plot significantly), the plot was a desired one , do you have any idea how to address such log of an exponential function?
Torsten
2022 年 6 月 20 日
log10(exp(-215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2)))) =
-215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2)) / log(10)
Maybe this helps.
Abdallah Qaswal
2022 年 6 月 20 日
I even put log 10 = 2.3, but still no desired results, here is the last modified code :
V1 = @(r,w) -acosh(10*(w/(1600*r + 21))^(1/2))/20000000000
V2 = @(r,w) acosh(10*(w/(1600*r + 21))^(1/2))/20000000000
% Define function to be integrated
fun = @(x,r,w)2.3*r.*0.0018./((w./((cosh(10^10.*x./0.5)).^2)-(r.*16+0.21)).^(1/2));
www = @(w,r)5.124+6.4*10^-6.*215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2)).*exp(-215.6*0.5*(w.^(1/2)-(r.*16+0.21).^(1/2)))./(integral(@(x)fun(x,r,w),V1(r,w),V2(r,w)))-(exp(-37.45.*r).*(70.31));
fimplicit(www,[0 5 0.001 0.075],'MeshDensity',500, 'LineWidth',1.5),grid
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
タグ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)