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)
  1 件のコメント
Sergio Manzetti
Sergio Manzetti 2018 年 1 月 25 日
Thanks Steven!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by