How do you determine the lower limit of an integral ?
2 views (last 30 days)
Show older comments
I am a new user of MatLab, and would like some help, since I do not know how to determine the lower limit in the link below:
The 8 boxes on the right represent the 8 possible answers, where the right answer is one of them. Of course I want to pick the right answer to this specific question, but I do not want someone to just give me the answer, since I would like to use the program to solve problems like this myself, but I just do not know how to get started.
So far, I have defined my function by the following command: f = @(x) 3*exp(-x.^2); and now I need help to what I need to do next, which commands I can use ect. I assume that there are more than one way to solve it, and I am eager to learn.
Have a nice day!
5 Comments
Walter Roberson
on 21 Sep 2017
You want to find a, so a has to be the variable that you are submitting to the anonymous function you are fzero'ing.
Accepted Answer
John D'Errico
on 21 Sep 2017
Edited: John D'Errico
on 21 Sep 2017
Split it into TWO problems.
fun = @(a) quad(@(x) 3*exp(-x.^2),a,1);
So, what does fun do? For ANY given value of a, it computes the integral, with defined limits of a and 1. We don't know what a is, at least not yet. But that does not matter. What we have is a function that computes the integral for any value of the lower limit. Try using fun.
On any thing like this, TEST IT OUT!!!! The trick to writing code for a problem that is too big for you is to break it into pieces, then test each piece. You can always put it all back together at the end. But before you go any further, verify that fun works.
fun(0)
ans =
2.2404724141465
Ok, so our goal is to find a value of a such that fun(a) is 1. fzero looks for a zero, but that is easy to fix. Note that I did not subtract off 1 from the kernel of the integrand.
But what if we wrote it like this?
fzero(@(a) fun(a) - 1,0)
So fzero sees a function that it wants to make zero. When it succeeds, it will have found a value of a such that fun(a) is 1. The starting point for the search is set here to 0.
It is easy enough to combine everything into one line if you want, but I usually recommend that you split things up. Two lines are not less efficient than one line. But one long complex line will often be much harder to read and debug.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!