如何在MATLAB中确定积分的上限来求解数值?
给定等式
对于某些给定函数f(x)
其中gamma
也给出了,如何才能数字上可以在matlab中求解上限u
?
f(x)
可以是任何模型的占位符。
这是一个从根角和集成问题的问题,但是由于我在MATLAB缺乏知识,我仍在努力弄清楚它是如何完成的。
我的最初解决方案是一种蛮力的方法。假设我们有
和gamma = 0.8
,我们可以从-inf
到u
by找到确定的积分从一些非常小的值u
中提取其积分,直到我们达到结果gamma = 0.8
。
syms f(x)
f(x) = (1/(sqrt(6*pi)))*exp(-(x^2/6));
gamma = 0.8;
u = -10;
res = int(f,x,-Inf,u);
while double(res) <= gamma
u = u+0.1;
res = int(f,x,-Inf,u);
end
fprintf("u is %f", u);
该解决方案非常慢,绝对不会一直工作。
我设置u = 10
,因为查看函数的图,我们实际上没有在间隔之外得到任何东西[-5,5]。
Given the equation
For some given function f(x)
where gamma
is also given, how can you numerically solve for upper bound u
in Matlab?
f(x)
can be a placeholder for any model.
This is a root-finding and integration problem but with my lack of knowledge in Matlab, I'm still trying to figure out how it is done.
My initial solution is a brute force approach. Let's say we have
and gamma = 0.8
, we can find the definite integral from -inf
to u
by extracting its integral from some very small value u
, working our way up until we reach a result gamma = 0.8
.
syms f(x)
f(x) = (1/(sqrt(6*pi)))*exp(-(x^2/6));
gamma = 0.8;
u = -10;
res = int(f,x,-Inf,u);
while double(res) <= gamma
u = u+0.1;
res = int(f,x,-Inf,u);
end
fprintf("u is %f", u);
This solution is pretty slow and will definitely not work all the time.
I set u = 10
because looking at the graph of the function, we don't really get anything outside the interval [-5, 5].
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用MATLAB符号数学工具箱(可能需要安装的附加组件)。
这样,您可以将自己定义一个“ true”不知道的变量x(不是x值数组),然后从负面的无穷大集成:
这使
gamma
作为来自>> inf
u
,在定义f(x)
为符号函数之后,将u
作为标量You can use MATLAB Symbolic Math Toolbox (an addon you might need to install).
That way you can define yourself a "true" unknow variable x (not an array of x-values) and later integrate from negative infinity:
This yields
gamma
as the integral from-Inf
tou
, after definingf(x)
as a symbolic function andu
as a scalar