I tried to evaluate this integral:
exp(7.313 x)/(x^2+1.7439)dx on the interval 0 to 0.001.
Then I had this kind of error : Unexpected MATLAB expression. So how do I write and evaluate it?
Thank you.

 채택된 답변

Star Strider
Star Strider 2014년 4월 10일

0 개 추천

I suggest:
f = @(x) exp(7.313.*x)./sqrt(x.^2+1.7439);
fi = integral(f, 0, 0.001)
produces:
fi =
760.0254e-006

댓글 수: 4

When I just copy and paste your suggestion I got a different answer I do not know why.
I got this following answer:
f = @(x)(7.313.*x)./sqrt(x.^2+1.7439);
>> fi = integral(f, 0, 0.001)
fi =
2.7689e-06
Which is totally different to 760.0254e-006
Thank you.
I have no idea. I also ran the same function and limits using quad:
q = quad(f, 0, 0.001)
and got:
q =
760.0254e-006
Try it with quad and see if you get the same result. If you get different results with integral and quad, something is wrong.
I am running R2014a. The integral function is relatively new, but I doubt there are version differences in quad.
I suggest you type:
which integral -all
in the Command Window, on the chance that you have your own integral function or variable that is ‘shadowing’ the built-in function. On my Windows 8 system, I get only one result:
C:\Program Files\MATLAB\R2014a\toolbox\matlab\funfun\integral.m
If you get more results than that, you need to rename your own integral function or variable. If you get a different result, and do not have the built-in integral function, use quad instead.
Matt Tearle
Matt Tearle 2014년 4월 11일
You're missing the exp in the numerator... :)
Star Strider
Star Strider 2014년 4월 11일
Good catch!
Didn’t see that. I assumed ‘copy and paste’ meant everything.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt Tearle
Matt Tearle 2014년 4월 10일

0 개 추천

Hard to say what's causing the error without seeing the actual MATLAB code you used. But regardless, if you just want the numerical value, you can do that using integral (or similar functions):
f = @(x) exp(7.313*x)./sqrt(x.^2+1.7439);
integral(f,0,0.001)
The first line creates a function handle that defines the function of a single variable (x). Note the use of vector operations (such as ./) because integral will evaluate the integrand at a bunch of points simultaneously.
The second line uses integral to do the quadrature.
(You can also do symbolic integration with Symbolic Toolbox.)

카테고리

태그

질문:

2014년 4월 10일

댓글:

2014년 4월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by