Trapz gives "Second and third argument must either be variables or a variable and a nonnegative integer specifying the number of differentiations."

16 ビュー (過去 30 日間)
Why does the following not work:
f_scalar = @(x) 5*x^2+3*x-4; g_scalar = @(x) -4*x^2+6*x+5;
f = @(vec) arrayfun(f_scalar,vec); g = @(vec) arrayfun(g_scalar, vec);
points = solve(f(x) == g(x), x);
h = @(x) g(x) - f(x);
vals = linspace(points(1),points(2),100);
disp(trapz(vals,h(vals)));
It gives "Error using sym/diff (line 36)
Second and third argument must either be variables or a variable and a nonnegative integer specifying the
number of differentiations."

採用された回答

Stephan
Stephan 2019 年 12 月 3 日
syms x
f_scalar = @(x) 5*x^2+3*x-4; g_scalar = @(x) -4*x^2+6*x+5;
f = @(vec) arrayfun(f_scalar,vec); g = @(vec) arrayfun(g_scalar, vec);
points = solve(f(x) == g(x), x);
points = double(points);
h = @(x) g(x) - f(x);
vals = linspace(points(1),points(2),100);
disp(trapz(vals,h(vals)));

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by