简体   繁体   English

我可以使用内置的Excel解算器以某种方式解决这个等式吗? 如果没有,你会怎么做?

[英]Can I use a built-in Excel solver to solve this equation somehow? If not, how would you go about it?

First of all, let me show you guys the equation in question. 首先,让我向你们展示一下这个等式。

CFL方程

In this equation S, V, and t are known constants. 在该等式中,S,V和t是已知常数。 CFL is also known. CFL也是众所周知的。 We have an initial value for D, and we have no idea what k is. 我们有D的初始值,我们不知道k是什么。

What I need to do is find ideal values for both D and k that would minimize the residuals squared of a calculated CFL and a measured CFL. 我需要做的是找到D和k的理想值,这将使计算的CFL和测量的CFL的残差平方最小化。 Using residuals squared is just a way for me to check if they're the best possible values, but it's fine if there's another way to go about this that uses some other method. 使用残差平方只是我检查它们是否是最佳可能值的一种方法,但如果还有另一种方法可以使用其他方法,那就没问题了。

The residual squared is just the absolute value of the difference between the calculated and measured CFLs, which is then squared. 残差平方仅是计算和测量的CFL之间的差值的绝对值,然后是平方。 The lower the residual squared, the better the fit we have. 残差平方越低,我们的拟合越好。 So I need the smallest possible residual squared resulting from putting both k and D into the equation. 所以我需要将k和D都放入等式中得到的最小残差平方。 That'll result in a calculated CFL, which I can then compare to a measured CFL, allowing me to calculate the residual squared. 这将导致计算出的CFL,然后我可以将其与测量的CFL进行比较,从而允许我计算残差平方。

My first idea for how to do this, since I'm not sure how to use Excel equations, was to fix the value of D (since we have an initial starting value to work from) and then vary through different values of k, putting them into the equation to find a calculated CFL, and comparing that to the measured to find the residuals squared, until I find one that results with the smallest residuals squared. 我对如何做到这一点的第一个想法,因为我不确定如何使用Excel方程,是为了修正D的值(因为我们有一个初始起始值来工作)然后通过不同的k值变化,放置将它们放入等式中以找到计算出的CFL,并将其与测量结果进行比较,找出残差平方,直到找到一个残差平方最小的结果。 Then I fix k at that ideal value, and vary D until I find the smallest residual there as well. 然后我将k固定在理想值,然后改变D直到我找到那里最小的残差。 Then I fix D again, and go back to varying k. 然后我再次修复D,然后回到变化的k。 My idea was that I could keep bouncing back and forth like that until both D and k were within a certain percentage of their previous values. 我的想法是,我可以像往常一样来回反复,直到D和k都在他们先前值的某个百分比之内。 I assumed it would reach some sort of equilibrium with this method 我认为它会与这种方法达到某种平衡

However, the numbers just go crazy, and end up either going to zero or going to infinity. 然而,数字只是变得疯狂,最终要么变为零,要么变为无穷大。 So I need to rework my process. 所以我需要重新修改我的过程。 Which is where you guys come in! 这是你们进来的地方!

How would you go about finding the most ideal values for both D and k, which would result in a calculated CFL closest to the measured one, assuming you are given values for every variable above apart from k? 你会如何为D和k找到最理想的值,这会导致计算出的CFL最接近测量值,假设你给出的每个变量的值都高于k? Remember to factor in that the value of D given initially is simply a starting place to work from, and is not the most ideal value. 请记住,最初给出的D值只是起作用的起点,并不是最理想的值。

I've been working on this program for a long time (at least a month), and I'm just stuck as hell and desperate. 我一直在研究这个项目很长一段时间(至少一个月),我只是陷入了地狱和绝望的境地。 I was hoping you guys could help me out. 我希望你们能帮助我。

Here are some initial values to work with: 以下是一些可以使用的初始值:

S = 19.634954 S = 19.634954

V = 12.271846 V = 12.271846

D (initial) = 0.01016482 D(初始)= 0.01016482

CFL (measured) = 0.401 CFL(测量)= 0.401

t = 4 t = 4

k = ? k =?

Thank you for any ideas you might have. 感谢您提出的任何想法。

You can't solve for two unknown variables in a 1 formula system. 你不能解决1公式系统中的两个未知变量。 However if I take D as given then you have a 1 unknown/1 formula system. 但是,如果我按照给定的D那么你有1个未知/ 1公式系统。

I just simply used 1 column as a guess of k (for me column B . I used another column to represent the calculated CFL with the guessed k (for me column C ). I have another column that has either a 1 or -1 (for me column D ). Lastly I have a column that represents the absolute value by which I want to increment my guess. 我只是简单地使用1列作为k的猜测(对于我的列B我使用另一列来表示计算的CFL和猜测的k(对于我的列C )。我有另一列具有1或-1(对于我的列D )。最后,我有一个列,表示我希望增加猜测的绝对值。

I named cells with the given values of the variables to make it easier to use them. 我使用给定的变量值命名单元格,以便更容易使用它们。

I started with a guess of k=1 . 我开始猜测k=1 Here are my formulas in my first row which was 7. 这是我的第一行中的公式,即7。

B7= .1 B7 = .1

C7 =(s/v)*(d/B7)^0.5*(ERF(((B7*t)^0.5))+((B7*t)/PI())^0.5*EXP(-1*B7*t)) C7 =(s/v)*(d/B7)^0.5*(ERF(((B7*t)^0.5))+((B7*t)/PI())^0.5*EXP(-1*B7*t))

nothing in D7 or E7 D7或E7中没有任何内容

in row 8: B8= B7+E8+D8 C8= =(s/v)*(d/B8)^0.5*(ERF(((B8*t)^0.5))+((B8*t)/PI())^0.5*EXP(-1*B8*t)) D8= 1 E8= .01 在第8行:B8 = B7+E8+D8 C8 = =(s/v)*(d/B8)^0.5*(ERF(((B8*t)^0.5))+((B8*t)/PI())^0.5*EXP(-1*B8*t)) D8 = 1 E8 = .01

in row 9 the B and C column is just copied down but D and E are as follows D9= =IF(C9>cfl,1,-1) E9= =IF(D9=D8,E8,E8/10) 在第9行中,B和C列只是向下复制,但D和E如下:D9 = =IF(C9>cfl,1,-1) E9 = =IF(D9=D8,E8,E8/10)

Once you get those in you can just copy down however many rows you want. 一旦你获得了这些,你可以复制你想要的许多行。

What this does is every time the residual of the CFL switches signs the increment's sign will also flip. 这样做的是每次CFL开关的残余符号表示增量符号也会翻转。 Additionally, the absolute value of the increment will also shrink by a factor of 10 to give more precision as it goes. 此外,增量的绝对值也将缩小10倍,以提供更高的精度。

This is by no means the best way to solve your problem but it is a way. 这绝不是解决问题的最佳方法,但这是一种方式。

As Dean said, your system has two unknowns, and in the general case an infinite number of solutions (different pairs of (D,k) ). 正如Dean所说,你的系统有两个未知数,在一般情况下有无数个解(不同的(D,k) )。 By fixing D , CFL is a continuous function of k , and as such, you should be able to find a k that gives the CFL you measured (within some accuracy). 通过固定DCFLk的连续函数,因此,您应该能够找到一个k ,它给出您测量的CFL (在一定精度内)。 For this problem (ie, finding k given CFL ) you can use the Goal Seek tool. 对于这个问题(即,找到给定CFL k ),您可以使用“ 目标搜索”工具。 Here is how: 方法如下:

1) Problem setup: Use the name of the variables to name the cells in which you input their values (Go to Formulas--> Defined Names --> Define Name and give some the name of each variable to a cell). 1)问题设置:使用变量名称命名输入其值的单元格(转到公式 - >定义名称 - >定义名称,并将每个变量的名称提供给单元格)。 Then input the values of your parameters in these cells, (give k an arbitrary value, eg = 1 ), and input the formula in cell CFL like: =(S/V)*SQRT(D/k)*(ERF(SQRT(k*t))+SQRT(k*t/PI())*EXP(-k*t)) Again, note that S,V,D,k and t are defined as named ranges. 然后在这些单元格中输入参数值(给k任意值,例如= 1 ),并在单元格CFL输入公式,如: =(S/V)*SQRT(D/k)*(ERF(SQRT(k*t))+SQRT(k*t/PI())*EXP(-k*t))再次注意, S,V,D,kt被定义为命名范围。

2) Problem Solution: Go To Data --> Data Tools --> What-If Analysis --> Goal Seek and enter the following parameters: Set Cell: CFL To value: 0.401 By changing cell: k 2)问题解决方案:转到数据 - >数据工具 - >假设分析 - >目标搜索并输入以下参数:设置单元格: CFL到值: 0.401通过更改单元格: k

This gave me k=0.151759378 , which results in CFL = 0.401261265054823 . 这得到k=0.151759378 ,其导致CFL = 0.401261265054823

在此输入图像描述

I hope this helps? 我希望这有帮助?

Edit : Finding some solution pairs using VBA: 编辑 :使用VBA查找一些解决方案对:

1) Place the measured CFL value in a cell (I chose H2 ). 1)将测量的CFL值放在一个单元格中(我选择H2 )。

2) Replace named ranges k , D and CFL . 2)替换命名范围kDCFL I used rngK , rngD and rngCFL , each one starting from row 2 till row 20. 我使用了rngKrngDrngCFL ,每个从第2行到第20行。

3) Fill down rngD with a step (I took 0.01) using the formula =INDEX(rngD,ROW()-ROW($C$2))+0.01 . 3)使用公式=INDEX(rngD,ROW()-ROW($C$2))+0.01 ,用步骤(我用0.01)填写rngD The first entry of rngD is in cell C2 and has the value 0.01016482 . rngD的第一个条目位于单元格C2 ,其值为0.01016482 The formula is copied down to all other cells in the range. 公式将向下复制到范围中的所有其他单元格。

4) Fill down rngK with some initial values (I took =1 ). 4)用一些初始值(我取=1 )填写rngK

5) Fill down the rngCFL range with the formula =(S/V)*SQRT(INDEX(rngD,ROW()-ROW($G$1))/INDEX(rngK,ROW()-ROW($G$1)))*(ERF(SQRT(INDEX(rngK,ROW()-ROW($G$1))*t))+SQRT(INDEX(rngK,ROW()-ROW($G$1))*t/PI())*EXP(-INDEX(rngK,ROW()-ROW($G$1))*t)) . 5)用公式=(S/V)*SQRT(INDEX(rngD,ROW()-ROW($G$1))/INDEX(rngK,ROW()-ROW($G$1)))*(ERF(SQRT(INDEX(rngK,ROW()-ROW($G$1))*t))+SQRT(INDEX(rngK,ROW()-ROW($G$1))*t/PI())*EXP(-INDEX(rngK,ROW()-ROW($G$1))*t))填写rngCFL范围=(S/V)*SQRT(INDEX(rngD,ROW()-ROW($G$1))/INDEX(rngK,ROW()-ROW($G$1)))*(ERF(SQRT(INDEX(rngK,ROW()-ROW($G$1))*t))+SQRT(INDEX(rngK,ROW()-ROW($G$1))*t/PI())*EXP(-INDEX(rngK,ROW()-ROW($G$1))*t)) I use the ROW() and INDEX() functions to refer to the Range element I need. 我使用ROW()INDEX()函数来引用我需要的Range元素。

6) Finally, use this code in a sub: 6)最后,在sub中使用此代码:

Dim iCnt As Long
For iCnt = 1 To Range("rngk").Count
    Range("rngCFL")(iCnt).GoalSeek goal:=Range("H2"), changingCell:=Range("rngK")(iCnt)
Next iCnt

The above generates 19 pairs (D,k) that give the measured CFL value. 以上产生19对(D,k) ,其给出测量的CFL值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM