【发布时间】:2018-03-08 13:01:43
【问题描述】:
我有以下方程要解:
aRatio = ((sqrt_gamma_ratio * (1/m) * ((1 + (squared_m_coefficient * m^2))^num_exponent))/ denom);
其中变量 aRatio、sqrt_gamma_ratio、squared_m_coefficient、num_exponent 和 denom 都是已知常量(分别为 1、1.046、.14、4.07 和 1.728)。就在上面的代码之前,m 是符号定义的。这是我的一些代码的一部分,其中包括迭代,所以我需要一些帮助来提出一种近似m 的通用方法(不必太准确,我会说百分之几就可以了)。我试过使用vpasolve函数如下:
f = vpasolve(aRatio == ((sqrt_gamma_ratio * (1/m) * ((1 + (squared_m_coefficient * m^2))^num_exponent))/ denom), m);
但它只是返回
Empty sym: 0-by-1
所以,Matlab 似乎无法象征性地解决它。我猜我必须采用我不太熟悉的数值方法。长期目标是建立m 作为aRatio 的函数。最终,我希望为aRatio 创建一个值数组,其范围为1-1000,间隔为10。这样我可以(希望)生成aRatio 与m 的图。这将通过使用 while 循环的迭代来完成。我计划更改一些其他变量,但我认为如果我能在这部分问题上获得帮助,它可能会有很长的路要走。
我的问题是为什么 Matlab 不能用符号方式解决这个相对简单的方程,我有什么替代方案?我已经广泛搜索了这个,我很困惑。
编辑:这是相关代码
gam0 = 1.4; %specific heat ratio in middle of nozzle
gamE = 1.28:-.01:1.20 ; %establish exit sp heat ratio variation
denom = 1.728; % this is the denominator of the given eqn, evaluated at g* =
1.4
aRatio = 1:10:1001;
count = 1;
mach_number = zeros(1,length(aRatio));
以下代码用于调试目的,它属于while循环。 我认为我需要一个嵌套的 while 循环来迭代游戏,但这真的不是我现在的问题。我想要的只是为 m 取回一个值,我还没有这样做
sqrt_gamma_ratio = sqrt(gam0 / gamE(1)); %1.046
squared_m_coefficient = .5 * (gamE(1) - 1); %.14
num_exponent = (gamE(1) + 1)/(2 * (gamE(1) - 1)); %4.07
注意:上面存储的值只是来自 gamE 的第一次迭代,也将在最终产品中进行迭代,但我对循环非常满意;让我头疼的是 Matlab!
f =((sqrt_gamma_ratio * (1/m) * ((1 + (squared_m_coefficient*
m^2))^num_exponent))/ denom)-aRatio;
fn = fzero(matlabFunction(f),1);
当我跑步时,我得到了这个:
Operands to the || and && operators must be convertible to logical scalar values.
老实说,我不知道这意味着什么或如何解决它。我想我至少必须靠近?
下面是我希望有一天能完成的 while 循环。对于那些有兴趣的人,我正在尝试获取大约 8000 个数据点,我会将它们全部存储在一个数组中,但基本上都是关于将 m 作为 aRatio 的函数,一旦我知道了,我就有了迭代上面的游戏变量,这应该是小菜一碟。 PS如果你喜欢,你可以在下面嘲笑我不满意的循环。
%{
while( count < length(compressive_area_ratio)+1 )
sqrt_gamma_ratio = sqrt(gam0 / gamE(1));
squared_m_coefficient = .5 * (gamE(1) - 1);
num_exponent = (gamE(1) + 1)/(2 * (gamE(1) - 1));
this_M = solve(compressive_area_ratio(count) == ((sqrt_gamma_ratio *
(1/m) * ((1 + (squared_m_coefficient * m^2))^num_exponent))/ denom), m );
disp(this_M);
%mach_number(count) = this_M;
count = count + 1;
end
%}
%plot(compressive_area_ratio, mach_number);
有什么想法吗?
【问题讨论】:
-
将
aRatio移动到另一边并使用fzero -
试过了。没运气。它说我不能使用符号或类似的东西。或者它不会再返回任何东西,这取决于我如何调整代码
-
您可以添加minimal reproducible example 以便我们进行测试吗?
-
请看我上面的编辑。如果需要,请随时要求澄清。我有点睡眠不足,所以如果我表现得有点分散,我不会感到惊讶
标签: matlab loops iteration numerical-methods equation-solving