Defining the limits of an integral
1 回表示 (過去 30 日間)
古いコメントを表示
I need to find the bounds of an integral in the following way:
I need to give an a number, which will be the value of the integral, and the output of the matlab/octave function will be b.
My code gives me a correct number, but it gives warning messages also, so what can be the problem?
This is my code: (I made it in Octave)
function first(a)
f = @(x)(1/sqrt(2*pi)).*exp((-1/(x.^2)));
intf = @(b) quad(f,-b,b);
b = fzero(@(b) intf(b) - a,0)
endfunction
And this happens when a = 1
warning: division by zero
warning: called from
first>@<anonymous> at line 3 column 25
first>@<anonymous> at line 4 column 15
first>@<anonymous> at line 5 column 26
fzero at line 290 column 10
first at line 5 column 5
warning: division by zero
warning: called from
first>@<anonymous> at line 3 column 25
first>@<anonymous> at line 4 column 15
first>@<anonymous> at line 5 column 26
fzero at line 290 column 10
first at line 5 column 5
.
.
.
warning: division by zero
warning: called from
first>@<anonymous> at line 3 column 25
first>@<anonymous> at line 4 column 15
first>@<anonymous> at line 5 column 26
fzero at line 290 column 10
first at line 5 column 5
b = 2.6582
Can you help me?
0 件のコメント
採用された回答
Star Strider
2019 年 6 月 27 日
You forgot to use element-wise operations in the division in ‘f’:
f = @(x)(1/sqrt(2*pi)).*exp((-1./(x.^2)));
↑
When I corrected that and ran this:
a = 1;
f = @(x)(1/sqrt(2*pi)).*exp((-1./(x.^2)));
intf = @(b) quad(f,-b,b);
b = fzero(@(b) intf(b) - a,1)
it produced:
b =
2.658202700888970
Note that I also changed the inital estimate from 0 to 1. That preven ts an infinite initial result.
2 件のコメント
Star Strider
2019 年 6 月 27 日
As always, my pleasure!
I have no experience with Octave. When I did an Interweb search just now, apparently Octave handles element-wise operations with the same ‘dot’ operators, however it also appears to require them for addition and subtraction.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Octave についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!