# Charting a mathematical equation using Excel and defined names

## Sample Equations

I'd like to invite the readers to provide nice sample equations!

Contact me when you have found some nice examples to add here.

A sample file can be downloaded here.

File crashes Excel!!

Save my workbook!The best tool for salvaging problematic workbooks.

Trainings

Excel VBA Masterclass (English)Excel VBA for Financials (Dutch)

Third party tools

Speed up your file

FastExcelThe best tool to optimise your Excel model!

Repair your file

Stellar Phoenix Excel RepairBest tool to repair corrupt Excel sheets and objects

I'd like to invite the readers to provide nice sample equations!

Contact me when you have found some nice examples to add here.

A sample file can be downloaded here.

## Comments

All comments about this page:

Comment by: Russ Kelley (2/28/2009 2:49:19 PM)

"Worksheet contains one or more invalid references. Verify that formulas have valid path, workbook, range name and cell refrence."

I get this error when opening some of the provided links in your tutorial to some examples. I am using excel 2007.

Comment by: Jan Karel Pieterse (3/1/2009 11:31:19 AM)

Could you email me a copy of your file please? (See address below this page)

Comment by: Plodder (6/23/2009 4:13:39 PM)

Thats a very useful article.

But when I was trying it in practice, I seem to have difficulty entering the name sheet1!x as an offset function (Sheet1!$A$12,0,0,xnumberofpoints,1) - it does not seem to stay as an array and hence the result is not calculated.

I use MS excel 2007 - could hat be the cause of the problem?

Comment by: Jan Karel Pieterse (6/23/2009 11:47:04 PM)

Excel 2007 is a bit picky about setting this up for a chart and I must admit I have not tried to set the chart up from scratch in 2007 yet. Something for my list of things to do I guess!

Comment by: Ernst van der Merwe (9/2/2009 1:32:59 AM)

I have used different angles of charting for various reasons and purposes. The two aims I always have in mind were to reduce memory use on the one hand, and speeding up processing.

I have build many models involved graphs included VB and VBA coding. This method of graphing equations have enormous potential. I am thinking in terms of plotting algorithms.

Thanks and I will stay in touch.

Ernst

Comment by: John (11/10/2010 10:31:43 AM)

Comment by: Jan Karel Pieterse (11/11/2010 8:40:34 AM)

Which Excel version are you using?

Comment by: John (11/11/2010 6:43:06 PM)

Comment by: Jan Karel Pieterse (11/11/2010 10:53:10 PM)

Odd, it works fine for me. Did you enable macro's and such?

Comment by: John (11/12/2010 10:46:34 AM)

Comment by: Jan Karel Pieterse (11/13/2010 11:57:44 AM)

Comment by: John (11/13/2010 5:44:19 PM)

I tried to genrate another x-y chart. A message came out: "A formula in this worksheet contains one or more invalid referenced. Verify that your formulas contain a valid path, workbook, range name, cell reference." when tried to type "=Sheet1!y" in the field of Y values. It's no problem when I entered "=Sheet1!x" in X values field.

Comment by: John (11/13/2010 6:02:24 PM)

Sorry I made a mistake when I tried to create another x-y chart: I forgot to enable macro.

After I enabled the Macro, I could create another x-y chart by entering "=sheet1!x" in the field of X Values and "=sheet1!y" in the field of Y Values. And the curve appeard in the new chart, but not in the old chart.

After I saved as, both charts displayed correctly. But when I quitted EXCEL and reopen the file, both charts have no cuves, only one point (-10,1).

It seems the chart couldn't get y. When I typed "=y" in a cell, it showed correct value: 126

Comment by: Jan Karel Pieterse (11/14/2010 7:03:33 AM)

OK, thanks for trying. I'll investigate this as soon as I have a bit of time.

Comment by: John (11/17/2010 6:47:09 PM)

Change the definition of Y from =EVALUATE(Sheet1!$B$1 & "+0*x") to ==EVALUATE(Sheet1!$B$1)+0*x

After save, close, then open the file again, the curve appear beatifully. It seems EXCEL 2003 doesn't support the old macro function EVALUATE perfectly.

Comment by: Carlos (2/12/2011 1:21:52 PM)

¿Cómo se puede graficar dos o más ecuaciones matemáticas en un mismo plano cartesiano.

Gracias

Hello.

How do you graph two or more mathematical equations in a single Cartesian plane.

Thanks

Comment by: Jan Karel Pieterse (2/13/2011 8:37:42 AM)

On the previous page :

http://www.jkp-ads.com/Articles/ChartAnEquation04.asp

I describe how to define the Y range name. For each equation you want to display, you have to create one separate Y range name and a separate Formula range name:

Sheet1!Y_1, Sheet1!Y_2

and

Sheet1!Formula1 and Sheet1!Formula2

Comment by: Alan Forster (3/4/2011 9:31:24 AM)

I would like to use a user defined function in the Evaluate function, is this possible?

Thanks,

Alan.

Comment by: Jan Karel Pieterse (3/7/2011 6:29:00 AM)

I think the best way to find that out is by trying!

Comment by: Alan Forster (3/7/2011 9:06:41 AM)

I did try, but it did not work. I wondered if there was another little trick like adding the + 0*x.

Evaluate is a poorly documented feature and I have struggled to learn much about it. As I type I wonder if it requires the function to be volatile? I will give it a go and report back if it works.

Thanks,

Alan.

Comment by: Jan Karel Pieterse (3/7/2011 10:41:15 AM)

OK. I guess you should make the UDF volatile.

I'm interested to learn your result!

Comment by: Alex Young (7/5/2011 6:13:19 AM)

How complex can the formula be? I have a situation with plenty of logic arguments, IF & ANDs - I can make it work using two IFs but any more than that and it fails. Its a long formula but it is correct, I've substituted the x for a value and calculated it and it comes up with the correct answer.

Any help you can offer would be appreciated,

Thanks,

Alex

Comment by: Jan Karel Pieterse (7/5/2011 6:37:12 AM)

I don't really know, maybe the formula cannot be longer than about 250 characters?

Comment by: Alex Young (7/5/2011 6:52:17 AM)

Is there any way to introduce other variables through the EVALUATE function? Or otherwise split up long formulas? I have worked out basic addition/subtraction already.

Regards,

Alex

Comment by: Jan Karel Pieterse (7/6/2011 4:44:18 AM)

Comment by: Laertes Boechat (11/28/2011 4:08:58 AM)

Thanks for the tip. Great idea.

Comment by: Jared (3/7/2012 10:30:56 AM)

This is a very creative solution to graphing equations in excel. I have been attempting (unsuccessfully) to build a graph that plots two (2) equations using your trick. I'm not a pro with using the defining tools so I don't know if what I am trying is even theoretically possible.

Any thoughts?

Jared

Comment by: Jan Karel Pieterse (3/8/2012 2:54:16 AM)

Comment by: Graeme (8/9/2012 4:31:29 PM)

The inputs are in three cells:

B1 log(2*x) [ Formula: the function being plotted ]

D1 -10 [ xStart: the independent variable starting value ]

E1 10 [ xEnd: the independent variable ending value ]

The named ranges parameters are as follows:

Name Value Refers To

1: Formula log(2*j) =Sheet1!$B$1

2: x {...} =xStart+xRange/(xNumberOfPoints-1)*(ROW _

(OFFSET(Sheet1!$A$1,0,0,xNumberOfPoints,1))-1)

3: xStart -10 =Sheet1!$D$1

4: xEnd 10 =Sheet1!$E$1

5: xNumberOfPoints 100 =100

6: xRange 20 =xEnd-xStart

7: y {...} =EVALUATE(Sheet1!$B$1 & "+0*x")

All the above works perfectly.

However, I wish to be able to modify the above so it is able to plot functions with the independent variable other than x, say j, so I add an eighth named parameter Var, which holds the variable j for use in the formulas.

Name Value Refers To

8: Var j =Sheet1!$C$1

I then set the four input cells as follows:

B1 log(2*j) [ Formula: the function being plotted ]

C1 j [ Var: the independent variable ]

D1 -10 [ xStart: the independent variable starting value ]

E1 10 [ xEnd: the independent variable ending value ]

To date, I haven't been successful in getting the Excel plotting tool to plot the function when the independent variable is specified in cell C1.

I would be most grateful for any assistance.

Comment by: Jan Karel Pieterse (8/9/2012 7:37:22 PM)

Can you email the workbook to me along with an explanation inside? (email address near bottom of this page)

Comment by: Jean Blair (8/31/2012 12:23:36 AM)

=EVALUATE('cost curves'!$B$17&"+x*0")

Any suggestions as to what I might be doing wrong? I am using excel 2011.

Thanks!

Comment by: Jan Karel Pieterse (8/31/2012 11:37:54 AM)

If I look at that formula, the value of x will not matter, since it is multiplied with zero.

Comment by: Jake Warren (11/15/2012 10:41:30 PM)

Comment by: Brian (2/20/2014 5:49:05 PM)

I was excited to find this tutorial. Unfortunately I can't make it work. However, the downloaded zip works fine.

The problem is that when modifying the chart line SERIES, an error popups informing that there are invalid references or formulas.

I've taken care to ensure the defined names and formulas are exactly the same as those found in the zip. I've go so far as to change the file type from 2010 to 97-2003.

Please help - I'd like to learn this technique.

Thank you,

-brian

Comment by: Jan Karel Pieterse (2/20/2014 6:41:20 PM)

Unfortunately, Excel 2003 worked just fine, but later versions seem not to like this technique very much.

I lack time to try and figure out what is wrong though, sorry!!

Comment by: Raj (6/4/2015 7:30:39 AM)

xStart=-4

xEnd = 4

xNoOfPoints=99

Formula=(sqrt(cos(x))*cos(500*x)+sqrt(abs(x))-0.4)*(4-x*x)^0.1

Comment by: Raj (6/5/2015 3:25:51 PM)

y=evaluate(formula)+0*x

and saving workbook in xlsm format (Macro Enabled Work Book)

Comment by: Shubhangi (6/23/2015 9:11:43 PM)

Comment by: Jan Karel Pieterse (6/24/2015 11:30:06 AM)

Enter sin(x) in cell B1

Enter 0 in b3

Enter 6.28 in B4

Enter 2000 in B5

Comment by: CoolKoon (11/28/2015 10:38:32 PM)

Comment by: Jan Karel Pieterse (11/30/2015 12:14:20 PM)

The download file works just fine in Excel 2016, so I figure something else must be wrong with your attempt to replicate.

Comment by: Alfred (8/5/2016 5:14:47 AM)

1. The scope of each and every named range MUST be the sheet that the chart is on.

2. Each and every formula that references the named range, MUST include the sheet name eg. Sheet1!Formula

3. The suggestion to add +0*Sheet1!x to the EVALUATE function will allow the workbook to open without producing an error message about one or more names not being correct.

4. If the formula to chart starts with a negative the addition of ' at the beginning will prevent Excel from trying to turn the entry into a formula for cell B1 eg. '-2*x^2+1

## Have a question, comment or suggestion? Then please use this form.

If your question is not directly related to this web page, but rather a more general "How do I do this" Excel question, then I advise you to ask your question here: www.eileenslounge.com.