필터 지우기
필터 지우기

Solve integral with a power

조회 수: 2 (최근 30일)
Sylvain
Sylvain 2014년 3월 6일
답변: Sylvain 2014년 3월 6일
Hi,
I try to solve the integral of an exponential function. Here is my code :
a1 = -0.0024 ; a0 = 0.0581 ;
fun1 = @(s,a,b) exp(a*s + (1/2)*b*(s^2)) ; fun2 = @(s) fun1(s,a0,a1) ; z = integral(fun2,10,45) ;
Matlab says : _____ Error using ^ Inputs must be a scalar and a square matrix. To compute elementwise POWER, use POWER (.^) instead. _____
If I use .^ there is no more problem, but I don't understand why s is not considered as a scalar. Does someone have some clue ?

채택된 답변

Roger Stafford
Roger Stafford 2014년 3월 6일
The quadrature routine 'integral', in the process of computing an integral, will call on its given integrand function with vectors of values of the variable of integration. For that reason, the integrand function must be written so as to be able to accept vector inputs rather than one scalar at a time. Therefore you need ".^" as your power operator. The documentation at:
http://www.mathworks.com/help/matlab/ref/integral.html
states that "Integrand, specified as a function handle, defines the function to be integrated from xmin to xmax. For scalar-valued problems, the function y = fun(x) must accept a vector argument, x, and return a vector result, y."

추가 답변 (1개)

Sylvain
Sylvain 2014년 3월 6일
Thanks for the answer.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by