Calculus II Applied Project - Graphing Section - Help with Excel

I Am Robot
Messages
12
Reaction score
0

Homework Statement



This is the third problem of a project for a Calculus II course. My issue is with graphing. Below is the problem, and below that my tutors explanation via e-mail to try and help me. I understand everything thus far, except for how I go about graphing. I am not strong in Excel. Problems four and five, as found in the pdf attachment or linked http://www.stewartcalculus.com/data/ESSENTIAL%20CALCULUS%20Early%20Transcendentals/upfiles/projects/ess_wp_0808_stu.pdf" , use the graph as well, so its important I do graph it.
number3.jpg



Homework Equations



beginning.jpg


The Attempt at a Solution


 

Attachments

Last edited by a moderator:
Physics news on Phys.org
Why on Earth would you try to use Excel for that? Use something like Maple.
 
I have never used Maple, sadface. Is it easier to input larger equations in Maple than Excel? The Excel operators seem alright for my physics labs, but I am dumbfounded here.
 
I'm going to second the above post, if it is not absolutely required of you to use excel, it is much easier to use math-ready software. I personally love matlab. If you've ever used any programming language, you should pick it up rather quickly. Even if not, it's still rather self explanatory on a lot of things, and for those that are not the help files are very good.

------------------------
I haven't used excel in a long time and don't have it on my computer, so if there's any errors I apologize. I don't know of excel having any ability to graph functions like that built in. Maybe there is, but I doubt it.

However, as far as computers go, anything you can do in some language or software you can do in a ton of other languages or software, you just may have to do a lot of the legwork that's already been done for you in the way of pre-defined functions.

If you wanted to use excel for graphing a function, I guess you could do the following:

cell A1: "wavelength" or "lambda"
cell A2: "energy density" or "function value"

Those are just going to be your labels for the graph.

now, about graphing. Let's use f(x) = x^2 as an example, graphed from x= -1 to x = 1.

Set cell A2 as "-1".
Set cell A3 as "=A2+.01"

the enter sign means you want the cell to do some sort of calculation, as opposed to display the text you enter. So, what displays in A3 should be: "-.99".

Now, make sure A3 is highlighted. there should be a little box in the bottom right corner, click it and drag it wayyyyyy down. All the way to cell A202. It should auto update the cell for you so that it always just adds .01 to the cell above it.

You should be looking at a list of numbers from -1 to 1, in increments of .01

Go back up to the top. Put cell B2 as "=A2*A2". Again, click and drag it down all the way to B202, using the little box in the corner. This should give you a list of values, such that the number in Bx is always the number in Ax squared. Now, you need to graph these. So highlight the block of cells with corners: A1, B1, A202, B202.

This is where my memory is a little fuzzy. So your going to have to play around with it, but this is the gist (make sure the cells are highlighted before you do this):

On the menu on the top,

insert > chart(or graph, not sure)

Tell it you want to make a line chart. Press ok a bunch of times. At some point it's going to give you a chart options page, where you can label the things like the x and y axis, set the scale, etc. Choose whatever fits your needs best, but you'll probably at least want to display grid lines to make it easier on yourself. Sorry, I wish I could be more helpful but, again, don't have excel on the computer.

Although, for problem 4, it would probably just be easier (and more accurate) to look at the data in your spreadsheet and find the values that are closest to what your looking for. Specifically, you could do this:

In cell C3, put "=B3-B2"

This is just going to be the change between the two points. Since B3 is to the right of B2 on the graph, if this number is positive, it is increasing, if it is negative, decreasing. Do the box-drag-down thing again to C202, and take a look at the data.

Find all the points where it changes from positive to negative. From your knowledge of derivatives, you should know there is a local maximum inbetween these two points. Conversely, negative to positive implies a local minimum.

If you followed the instructions above with the numbers I put in exactly, then the last negative cell should be C102, and the first positive cell should be C103. So you know the local minimum of f(x) = x^2 is located in the closed the values of A102 and A103. For f(x) = x^2, it's obviously 0. Which should be cell A102.

-------------------

As a side note, I doubt any of the constants are pre-defined in excel (even pi, although I could be mistaken), so you will have to enter them in manually.

-------------------

If you decided to go with matlab, you could have just done the following:

x = -1:.01:1;
f = x.^2;
plot(x,f), xlabel('x'), ylabel('f');

So I highly recommend learning it. You will not be unhappy with yourself in the long run. Once you get good at it you can also interface it with C programs and all sorts of fun stuff. Also, part 4 would be very easy once you have the graph window open. You wouldn't need to figure out the differences between points or any of that nonsense.

-----------------

The MATLAB code really does exactly the same thing.

The first line makes a matrix with values going from -1 to 1, with increments of .01.

The next line makes a matrix with values that are equal to the square of the values in correlating places in the matrix x.

The rest should be pretty obvious ;)

At any rate, it should be easy to see what's going on here. The software can't graph like we do, it just plugs in a ton of points and puts them down and tries to connect the dots as good as possible. That's why excel will give you essentially the same results as any other software.

This brings up something related: The smaller the intervals between points are, the more accurate your graph will be. For instance, if you graphed

sin(2pi*x) from x=1 to x=100

using the method i described above, but you set yourself to have points of distance 1 apart, your just going to get a straight line. You see where I'm going with this. The same is true with MATLAB or anything else like that. It doesn't know what sine is, it just plots a bunch of points. So if the graph doesn't look like what you think it should, don't trust the computer and change the parameters.

*gasp for air* lol

EDIT: changed " to ' in the MATLAB code. Got my syntax all mixed up :)
 
Last edited:
osnarf! Thank you. I am working on that Excel sheet now.

I am trying to acquire a copy of Matlab as the University I am transferring to told me if I learn Matlab I could help with research as a sophomore. I'll find a copy and then try out your conditions.
 
Great, you won't regret it. The student edition is $100 on their website, I believe. I usually just go to the engineering lab on campus, because my hard drive crashed and I lost my copy so I have to wait until next months financial aid, lol.

If you live close enough to a university you should check it out, there's probably a comp lab with MATLAB on it. If not a lot of CC's now have it too. The lab is supposed to be for engineering majors, but if you explain to them what's going on (and the lab isn't full), I really doubt they'd have a problem with letting you on.

If you do check into matlab, two tips:

--after you get the basics down, read what an "m file" is. It's really not a very good idea to just enter commands into the command line for big projects, although if you need it for something quick (like to use it as a bigger and better calculator), it's fine to just type the commands in.

---Notice I put .^ in line 2 of the MATLAB code. The dot signifies that you want to perform the operation on each element of the matrix. If you leave it out, for instance:

x = 1:1:2:
gives you x = (1, 2);

if you type x.^2, it gives you ans = (1, 4).
if you type x^2, it gives you an error, because you tried to multiply (1,2) * (1,2). This doesn't work because your trying to do matrix multiplication with matrices of incompatible sizes.

Just telling you to try to avoid the headaches it gave me :)
 
So I have inserted my equation, but the range, I don't quite follow where to go.

So far within I have the function: =((8*(3.1415926535)*(1.3807*(10^-23))*5700))/(x^4)

What happens with the variable 'x'? Is this when I would begin with a range of numbers and (x) be (A2) through (A50-100 or so)? Thereby inserting them as my zero to very large?
 
Exactly. You should just be starting in the top cell (excluding the label, so i'll assume B2). Then, you want the x to be the value in the cell to the left of the cell you are working on. So instead of x, put A2 (or whatever row you started with). When you do the drag-down thing, it will automatically update the '2' in 'A2' to whatever row you are working on.

Really what it does is just copy the formula down and add 1 to all the "variables" (cell names) you put in there. If you go down, it adds 1 to the number. If you go to the right, it adds one to the letter.

For instance.

if you had these values in the following cells:
A1: 11
A2: 21
B1: 12
B2: 22

And you then proceeded to put the following into cell C1
'=A1'

if I am not mistaken you should just be able to drag the box down 1 box and over to the right 1 box (so your cursor is on D2), and the cells will display the following:
C1: 11
C2: 21
D1: 12
D2: 22
 
Ha, I actually just found out I have excel starter on my computer. Go figure :) Let me know if you get stuck on the graphing part. If you have a recent version of excel I should be able to help.
 
  • #10
Apparently you have to drag over 1, release. Then, while still highlighted, drag down 1. It works though.
 
  • #11
They definitely changed the chart setup process since last I've used. If you can't figure it out let me know and I'll write up how.

Edit: battery dying so i'll just go ahead.

Just highlight the column your function values are in (column B probably for you). Insert, line graph. Then right click on the graph and click 'select data.' The right hand side of the box that pops up should say 'horizontal (category) axis labels. Click 'edit'. Now, on the spreadsheet, click and drag from the first point of DATA in your 'lamnda' or 'x' or w/e column (column A. If you put labels, don't click on the cell with the label, click undernieth it) all the way down to the last point of data. Click okay. Click okay again. Your graph should be set.

Double click on the title to rename it if you want. Right click and select the edit chart area option to change colors and whatnot.

----

Ps if you don't want something to change when you drag it, you can put $ in front of it. For instance, if you did what I said with the 11,12,21,22 thing, except in cell C1 you put $A$1(before you dragged), each of the 4 cells you dragged to would now display '11'.

If you put $A1, they would say:

C1: 11
C2: 21
D1: 11
D2: 21

If you put A$1, they would say:

C1: 11
C2: 11
D1: 12
D2: 12
 
Last edited:
  • #12
deleted
 
Last edited:
  • #13
I have been able to get my charts going decently, my only issue is a "DIVIDE BY ZERO" when I have the -1 in there. seen here:

dsddd.jpg


My initial value of A4 is 1nm. Not sure what the issue is.

=(((8*3.1415926535*(6.6262*10^-34)*(2.997925*10^8)))*(A4^-5))/(EXP(((6.6262*10^-34)*(2.999*10^8))/(A4)*(1.3807*10^-23)*5700))
 
  • #14
Sorry I didn't get back to you sooner, I was workin on my own problems lol I just assumed this worked. Know what they say about that...

I think I have a solution. I definitely know what's wrong. It's because Excel has a data type limit that is smaller than I thought, apparently. So long story short the calculation of the power of e is closer to 0 than excel has digits to store, so it thinks it really IS 0, and evaluates exp(...) as 1. This is why you should use MATLAB :) Although I'm sure you can run into this sort of error there, too, I haven't yet, and this is the first time I've tried it w/ excel and look what happens lol.

So we just need to optimize the code to work around that. Should be able to get it to work, though. Give me some time I'll get back to you. This isn't due tomorrow I hope? :(

I sent you a PM, btw.
 
  • #15
Alright, so I figured something out that works. I graphed my results from 1nm to 2000nm (which is a good range to get a good picture of the graph - except there's still some sort of error due to lack of precision for 1nm, 2nm, and 3nm, but it doesn't really matter) and compared it to ones I found online and it looks to be very accurate. Here is what I did:

I multiplied out 8*pi*h*c. I don't believe this part had anything to do with the problem, but it is always a good programming practice to do this sort of calculation beforehand and hard code it in. The reason is because I only had to do it once. However, the machine has to do it 2000 times. That's 8000 calculations. If this were a less nicely behaved function (you'll see what I mean when you graph it), and you wanted to see it's behavior over a large distance, you might need more than 2000 points. You might also want to see it's behavior over all temperatures from 300 K to 5700K, and use the 2000 points described above. Then its 10800000 calculations. Also, it will take less memory.

The problem was with the exp function. I really couldn't figure out why it was doing what it was doing, I was playing with it for a while. But if you do the same thing as above, it should work, because that's all I did and it came out good. I swear I had the same thing half an hour ago and it wasn't working, though... If I had to venture a guess, I would say the problem was with all the unsimplified exponents. At any rate, now you know why you should use MATLAB or maple or something lol. Another lesson on the limitations of computers.

Also make sure your units are right when you enter the wavelengths (should be entering 1x10^-9 for 1nm). If you start at 1 nm and go in increments of 1 nm, you don't need to worry about changing the x axis. Just highlight column B, and tell it to make a graph. It will automatically use the row numbers (which will be the correct number of nanometers) for x-axis markers.

Your graph should look like attached. Sorry, not allowed to post answers so I can't give you the exact formula and had to take numbers off graph.

Basically, multiply everything out and simplify exponents and hope for the best! :)

PS - When I multipled out everything I went online and found numbers with more significant figures to start with for the constants. I doubt it matters but if there's a slight difference between our graphs that's probably why.
 

Attachments

  • plancks law.jpg
    plancks law.jpg
    9.3 KB · Views: 439
  • #16
Just to reiterate why it is a good idea to use appropriate software, here's how easy it is to implement in Maple code:

restart;
h := 6.6262*10^(-34);
c := 2.997925*10^8*10^6; #units of micro-meters
k := 1.3807*10^(-23);

f := proc (T) options operator, arrow; 8*Pi*h*c/(lambda^5*(exp(h*c/(lambda*k*T))-1)) end proc;

#Comment, the above proc is actually entered by just typing the formula

> plot({f(3400), f(5700), f(6400), f(9200)}, lambda = 0 .. 3);
>

5 simple lines of code.
 
  • #17
Thank you both so much! So the project was due today, in a way. We had to present. This morning I went to school early and played around with Maple, within a half hour or so I was able to make a graph, totally incorrect, but a graph nonetheless to show during my presentation. Excel I gave up on after asking another classmate if they knew what was wrong. We tried a lot of different combinations, but never got anything close to your graph, osnarf.

My presentation ended up being fairly good, considering half of the class had no preparations of any sort and had done hand graphing, which was specifically not allowed, so good by comparison.

I borrowed a school laptop for tonight to use Maple. I will be playing around with the code you have given me, LCKurtz.

Thank you both for your help.

osnarf, without your help I would have been awfully embarrassed. I opened Excel and showed all my DIV 0s and the professor enjoyed it, apparently happy I even tried... low standards? :-( Looking into Matlab. Would really like to have a work study or research ability at my next school, and Matlab is the ticket.

Thanks :-D
 
  • #18
Haha, I bet the professor got a kick out of that; probably hasn't seen it attempted like that before (and for good reason). Anyways, glad it kind of worked out for you. Can't hurt to post it now, here is what I had in cell B1 if you were curious, lol:


=((4.99248207264021*10^-24)*(A1^-5))/(EXP(((2.52416694766301)*(10^-6)/(A1)))-1)

A1 started with .000000001, increased by .000000001 each time.
 
  • #19
Just to let you know, the Maple version I used was Maple 13. Earlier versions I can't vouch for. For your information, since you're done with the project, here's the plot:

graph4.jpg
 
  • #20
LCKurtz said:
Just to reiterate why it is a good idea to use appropriate software, here's how easy it is to implement in Maple code:

restart;
h := 6.6262*10^(-34);
c := 2.997925*10^8*10^6; #units of micro-meters
k := 1.3807*10^(-23);

f := proc (T) options operator, arrow; 8*Pi*h*c/(lambda^5*(exp(h*c/(lambda*k*T))-1)) end proc;

#Comment, the above proc is actually entered by just typing the formula

> plot({f(3400), f(5700), f(6400), f(9200)}, lambda = 0 .. 3);
>

5 simple lines of code.

osnarf said:
Haha, I bet the professor got a kick out of that; probably hasn't seen it attempted like that before (and for good reason). Anyways, glad it kind of worked out for you. Can't hurt to post it now, here is what I had in cell B1 if you were curious, lol:


=((4.99248207264021*10^-24)*(A1^-5))/(EXP(((2.52416694766301)*(10^-6)/(A1)))-1)

A1 started with .000000001, increased by .000000001 each time.

Ya, the professor definitely enjoyed it :)

Gorgeous graphs. Making me giddy! :) So nice seeing it all come to life. Amazing what 5 lines of code can do and a little factoring, haha. Using Maple 14 right now. I think that is the most up to date version.
 
Back
Top