Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Ali Baba
 
Posts: n/a
Default How to plot a formula with two variables

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??

  #2   Report Post  
Bernard Liengme
 
Posts: n/a
Default

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
--
Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email

"Ali Baba" wrote in message
...
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??



  #3   Report Post  
MrShorty
 
Posts: n/a
Default


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 0
because of rounding error when decimal fractions are converted to
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 exactly
what you've asked for, no less, and no more.

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


--
MrShorty
------------------------------------------------------------------------
MrShorty's Profile: http://www.excelforum.com/member.php...o&userid=22181
View this thread: http://www.excelforum.com/showthread...hreadid=471538

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding row to forumla carrera Excel Discussion (Misc queries) 9 August 23rd 05 10:24 PM
dragging a formula P Bates Excel Discussion (Misc queries) 3 August 7th 05 09:37 PM
Vary variables in a formula via reference to another cell Peter Excel Discussion (Misc queries) 2 July 21st 05 07:19 PM
Named SUM Formula with relative refernce(s) Werner Rohrmoser Excel Worksheet Functions 2 April 20th 05 04:56 PM
Cell shows formula and not the result of the formula. stumpy1220 Excel Worksheet Functions 2 January 14th 05 05:11 PM


All times are GMT +1. The time now is 12:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"