How to plot a formula with two variables

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I would like to plot a formula in this form
x + y = 0

I know u may say "rearrange it to y = -x" and plot it. This is not what I
want.

I tried to write a code to generate data on the worksheet but I was
unseccusseful

this is what I am trying to do

for x values,
y = -10
For x = 1 to 10
Cells(i,1) = x
Function = replace(function, "x", x)

Do
function = evaluate(replace(function, "y", y))
y = y + 0.1
loop until function = 0
Cells(i,2) = y-0.1

Next x

Can anybody help to write this code??
 
Why you should want to do this I cannot guess!
In column A (say A2:A22) enter the required x-values
In B (B2:B22) enter any y-values --- a series of 1's will do
In C2 enter =A2+B2 and copy down to C22
Open Solver, clear the Target box; the By changing should read B2:B22; add
constraint C2:C22=0; solve
Plot A2:B22
best wishes
 
Suspending judgement on why you want to do it this way:

Sub mysub()
Set rng=desired range
With rng
For x=1 to 10
y=-10.1
Do
y=y+.1
f=x+y
loop until abs(f)<1e-6
'I often prefer to test for almost 0 rather than exactly equal to
because of rounding error when decimal fractions are converted t
binary in the IEEE system
.cells(x,1).value=x
.cells(x,2).value=y
next x
end with
end sub

check the syntax, I wrote that quickly. Debugged, it should do exactl
what you've asked for, no less, and no more.

I'm guessing this is just a test case for future, more comple
problems. If this is true, you might consider looking into differen
numerical algorithms for solving f. A Newton-Raphson algorithm will b
more certain of finding a solution, and will find it more effecientl
than the algorithm we've used here. We also haven't dealt with case
(like x-y^2=0) where there is more than one possible y value for each
value. Bernard's approach using Solver in a worksheet will work wel
for most other equations, though it won't have a way of determinin
when multiple solutions exist
 
Back
Top