Home |
Search |
Today's Posts |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
adding row to forumla | Excel Discussion (Misc queries) | |||
dragging a formula | Excel Discussion (Misc queries) | |||
Vary variables in a formula via reference to another cell | Excel Discussion (Misc queries) | |||
Named SUM Formula with relative refernce(s) | Excel Worksheet Functions | |||
Cell shows formula and not the result of the formula. | Excel Worksheet Functions |