Problem in formatting a function

1 次查看(过去 30 天)
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 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by