简体   繁体   中英

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. CFL is also known. We have an initial value for D, and we have no idea what k is.

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. 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. 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. That'll result in a calculated CFL, which I can then compare to a measured CFL, allowing me to calculate the residual squared.

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. Then I fix k at that ideal value, and vary D until I find the smallest residual there as well. Then I fix D again, and go back to varying 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. 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? 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.

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

V = 12.271846

D (initial) = 0.01016482

CFL (measured) = 0.401

t = 4

k = ?

Thank you for any ideas you might have.

You can't solve for two unknown variables in a 1 formula system. However if I take D as given then you have a 1 unknown/1 formula system.

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.

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 . Here are my formulas in my first row which was 7.

B7= .1

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

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

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)

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. Additionally, the absolute value of the increment will also shrink by a factor of 10 to give more precision as it goes.

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) ). 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). For this problem (ie, finding k given CFL ) you can use the Goal Seek tool. 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). 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.

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

This gave me k=0.151759378 , which results in CFL = 0.401261265054823 .

在此输入图像描述

I hope this helps?

Edit : Finding some solution pairs using VBA:

1) Place the measured CFL value in a cell (I chose H2 ).

2) Replace named ranges k , D and CFL . I used rngK , rngD and rngCFL , each one starting from row 2 till row 20.

3) Fill down rngD with a step (I took 0.01) using the formula =INDEX(rngD,ROW()-ROW($C$2))+0.01 . The first entry of rngD is in cell C2 and has the value 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 ).

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)) . I use the ROW() and INDEX() functions to refer to the Range element I need.

6) Finally, use this code in a 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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