Problem in formatting a function

조회 수: 1 (최근 30일)
Sergio Manzetti
Sergio Manzetti 2018년 1월 24일
댓글: Sergio Manzetti 2018년 1월 25일
Hi I am trying to solve this intergral:
syms x h
h = 1.0545718E-34
f = exp.^(5.06E6.*i.*x+(1./h))+3/4.*exp.^(1./h)+i.*5.06E6./2.*exp.^(1./h)
integral(f, -pi, pi)
But it appears wrong. Can't get a proper indication on what is wrong in MATLAB online. Thanks!

채택된 답변

Steven Lord
Steven Lord 2018년 1월 24일
One problem specific to how you've written your code is that you're calling exp incorrectly. To compute the exponential of a variable z you need to use exp(z) instead of exp.^z.
In general:
  • To integrate a function that returns numeric values, use the integral function.
f1 = @(x) x.^2;
result1 = integral(f1, 0, 1)
  • To integrate a symbolic expression symbolically, use the int function.
syms x
f2 = x^2;
result2a = int(f2, x)
result2b = int(f2, x, 0, 1)
result2b1 = vpa(result2b)
result2b2 = double(result2b)
  • To integrate a symbolic expression numerically, use one of two approaches. Either use vpaintegral or convert the symbolic expression into a function that returns numeric values using the matlabFunction function and then use the integral function.
syms x
helper = x^2;
f3 = matlabFunction(helper);
result3a = vpaintegral(helper, 0, 1)
result3b = integral(f3, 0, 1)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by