Defining the limits of an integral
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Jack Wilson
il 27 Giu 2019
Commentato: Star Strider
il 27 Giu 2019
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 Commenti
Risposta accettata
Star Strider
il 27 Giu 2019
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 Commenti
Star Strider
il 27 Giu 2019
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Octave in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!