Error using feval on integral

14 ビュー (過去 30 日間)
Eric Junaeus
Eric Junaeus 2021 年 6 月 20 日
コメント済み: Walter Roberson 2021 年 6 月 20 日
When I type my feval in the Command Window, I get the error:
"Function to evaluate must be represented as a string scalar, character vector, or function_handle object."
function [Ih] = Trapets( f , a , b , N )
a=0;
b=pi;
N=100;
x=a:b/N:b;
f=sin(x^2);
h = (b-a)/N;
f0=feval( f , x );
Ih=h*(sum(f0)/N;
end
  2 件のコメント
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 6 月 20 日
There are a couple of crucial errs in your code and here is the fixed one:
a=0;
b=pi;
N=100;
x=a:b/N:b;
Ih = Trapets(a, b, N, x);
fprintf('Final value is: %f \n', Ih)
function Ih = Trapets(a, b, N, x) % Note Input vars
f=sin(x.^2);
h = (b-a)/N;
f0=f;
Ih=h*sum(f0)/N;
end
Walter Roberson
Walter Roberson 2021 年 6 月 20 日
No the posted code would fail before that. x is vector and ^2 of a vector is not defined (except for scalar)

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

回答 (0 件)

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by