matlab - 使用积分 : A and B must be floating-point scalars 时出错

标签 matlab integral

我要求积分的简单例子

a = max(solve(x^3 - 2*x^2 + x ==0 , x)); 
fun = @(x) exp(-x.^2).*log(x).^2;
q = integral(fun,0,a)

错误是

Error using integral (line 85)
A and B must be floating-point scalars.

有什么建议吗?我的积分下限必须是一个函数,而不是一个数字。

最佳答案

Matlab 命令 solve 返回符号结果。 integral 只接受数字输入。使用 double 将符号转换为数字。现在编写代码时,max 应该会因符号输入而引发错误。以下作品。

syms x;
a = max(double(solve(x^3 - 2*x^2 + x)));
fun = @(x) exp(-x.^2).*log(x).^2;
q = integral(fun,0,a)

输出:1.9331

the lower limit of my integral must be a function, not a number

integral 是一个数值积分例程;积分的限制必须是数字。

关于matlab - 使用积分 : A and B must be floating-point scalars 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29804749/

相关文章:

matlab - MATLAB 中结构多级索引的矢量化

r - 查找具有多个交点的两个图之间的公共(public)区域

c++ - 如何根据cpp模板中的实际类型调用整数类型?

matlab - 如何在 MATLAB 中从网格中创建字符串单元格?

Matlab 生成所有可能的团队组合

performance - 为什么 Matlab Profiler 说 'end' 循环的 'for' 语句存在瓶颈?

python - 对数组执行二重积分

c - 高斯积分和二分法

python - 用积分拟合方程,其中上限是变量

c - Matlab mex 没有 xcode,但有独立的命令行工具