Finding Values of X

J

Jeffrey

Good day,

im just a newbie in VBA, i wonder if we can find X using VBA codes to
satisfy the equation below.

X^2 -28X+16 = 0.

Basically i want to find the value of X so that the left side of the
equation is equal to zero.

Thanks in advance.
 
R

RB Smissaert

In Cell C1 put this formula:
= A1* (28-A1)

Load Solver by doing Tools, Add-ins and tick the Solver add-in.

Then Tools, Solver and

Set Target Cell C1
Equal to value of -16
By changing value of A1
Press Solve

To put it all in VBA do the same as above while recording a macro and study
the recorded code.


RBS
 
G

Gary''s Student

Nearly the same as the equivalent worksheet formulas:

=(28+(28^2-4*16)^0.5)/2
=(28-(28^2-4*16)^0.5)/2

which yield:

27.41640786
0.583592135
 
J

JLGWhiz

Or you can use the Quadratic theory:

Sub uo()
x = -(-28) + Sqr((-28) ^ 2) - (4 * 1 * 16) / (2 * 1)
MsgBox x
x = -(-28) - Sqr((-28) ^ 2) - (4 * 1 * 16) / (2 * 1)
MsgBox x
End Sub
 
J

JLGWhiz

Works better with all the parentheses in:

Sub uo()
x = -(-28) + Sqr(((-28) ^ 2) - (4 * 1 * 16)) / (2 * 1)
MsgBox x
x = -(-28) - Sqr(((-28) ^ 2) - (4 * 1 * 16)) / (2 * 1)
MsgBox x
End Sub
 
J

Jeffrey

Good day,

Hi guys, thanks much for your response. they work. but have to
rephrase my question.
i should have ask this one at the first place.


r = W^2 + 4(H^2)
----------------------
8H

Values given are "r" and "W". And im looking for H.
I would like the user to enter the value of r and W in say a1 and a2
respectively, and the value of
H will be given.

Please advice. Thanks in advance.
 
R

Rick Rothstein \(MVP - VB\)

Yes, asking the question you actually want answered would seem to make more
sense. Anyway, solving for H yields these two equations.....

H1: =R1+SQRT(R1*R1-W1*W1/4)

H2: =R1-SQRT(R1*R1-W1*W1/4)

Where I picked cells who column address matched your variable letters.

Rick

Good day,

Hi guys, thanks much for your response. they work. but have to
rephrase my question.
i should have ask this one at the first place.


r = W^2 + 4(H^2)
----------------------
8H

Values given are "r" and "W". And im looking for H.
I would like the user to enter the value of r and W in say a1 and a2
respectively, and the value of
H will be given.

Please advice. Thanks in advance.
 
R

RB Smissaert

OK, I thought that you had worked out that the value couldn't simply be
simply calculated.
As you can no need for Solver. Still, it may come in handy one day.

RBS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top