This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

I'm trying to make a program that draws a slope field based on a differential equation. I can evaluate the equation quite easily, but am having trouble drawing the lines. Is there any way to draw a line based on slope rather than (x,y) coordinate pairs?

Sure, that wouldn't be too difficult. You've heard of the tangent line, right? Once you calculate the slope, simply use an arbitrary (x,y) pair to find an equation for the line tangent to the graph at the (x,y) point.

Once, you have the line, I guess you could draw it with restrictions using bounds.

Last edited by Guest on 01 Mar 2010 09:30:13 pm; edited 1 time in total

The problem with the tangent line function is that it, unless I'm completely wrong, draws a line that continues till the end of the graph, which wouldn't work for a slope field, which needs small lines.

Can someone quickly refresh my mind on what a slope field is? I know that it is with all the little tick marks but can't remember what it is mapping out exactly. Like graph wise, I know the ticks are slopes. Wow, I'm confusing haha, hopefully that made sense somewhat.

Ya, thanks, I actually just checked my Calculus notes 'cause it was bugging me I couldn't remember haha. As for creating a program I only have an idea of how you could do it, though most likely very inefficient.
My idea is that, well first, have the user input the equation to make the field from. Then you would use some kind of loop (For( would work well I think) to check a series of points to fine the slopes. You could then have another loop inside that helps graph those lines with the Line( feature.
Like I said this is probably really inefficient and hard to program, though I will try later tonight if I have time to see if I can get it to work.

Last edited by Guest on 01 Jul 2010 09:29:42 am; edited 1 time in total

@ Meishe and Wesley: My problem is graphing the lines properly with the line() function. As it only accepts (x,y) coordinate pairs, I don't see how I can get it to draw a line of a certain slope. Of course, I could just be overlooking something simple as well...

@ Meishe and Wesley: My problem is graphing the lines properly with the line() function. As it only accepts (x,y) coordinate pairs, I don't see how I can get it to draw a line of a certain slope. Of course, I could just be overlooking something simple as well...

Oh ok. Hmmmm...well the derivative gives you the slope so you could simply use the For( to check those points to get slope values for that x-value. Easy enough I think. Now for making the lines...the inefficient part. The linear line equation, as I'm sure we all know, is y=mx+b so using another For( (where you are using this one for the b value) you could find for each line two points and store the points to A, B, C, D and plug those into the Line( command. I hope that makes sense, and hopefully you see why its inefficient.

Last edited by Guest on 01 Jul 2010 09:30:19 am; edited 1 time in total

Does it matter if you happen to know the derivative of the function? This would make it pretty easy.

Well that's what a slope field does. You have the derivative and plot those points (which are the slopes of the integral/anti-derivative) and those give you the general image of the graph. Then you would have to solve for the integral and the value of C (what I learned it as), which is just that value that you have to account for. Once you have that then you can graph the integral.

Last edited by Guest on 01 Jul 2010 09:30:48 am; edited 1 time in total

Now, if you knew the derivative, I would suggest a double For loop to set up a table of the slope lines (you need to draw each line at a time while stepping through each x and y pair.

Now, I would recommend, for the calculator to only use 9 slope lines drawn across the screen and up and down (it fits more nicely). In order to find the x and y coordinates corresponding with the screen values, you could use the following:

Now, if you knew the derivative, I would suggest a double For loop to set up a table of the slope lines (you need to draw each line at a time while stepping through each x and y pair.

Now, I would recommend, for the calculator to only use 9 slope lines drawn across the screen and up and down (it fits more nicely). In order to find the x and y coordinates corresponding with the screen values, you could use the following:

Then, building off of what I've shown earlier, we have an X value, so we could compute what our function is (assuming it's stored in a function, say Y1).

The next step would be how to draw the lines, right? Well, what if we set a sort of modularity within the function by using the trig functions? We could then take the inverse tangent of what the function Y1 returns.

Now, we have the hardest part to break down, the actual coordinates of the line. Now, I stored values in C and D before entering the loops. I had to fiddle with the constant in front to adjust the line size a bit, but that's all they are.

The line will have upper and lower bounds, with X and Y offsetting the values to position the lines correctly on the screen. We can then multiply our constants (which modify the length of the lines) by the cos(O) to find the highest X value, which will be similar for the Y's.

Notice that the second X and Y have a negative in front of the cos/sin, this is because the +X/+Y are the real modifiers of the correct positions, whereas the cos/sin are used to find where the slope is. Think back to trig where you fiddled with the unit circle and triangles.

A 9x9 slope field would be a bit too small, I think. In fact, I made a part of the program that sets the window variables, does the for() loops based on them (i.e. for(A,xmin,xmax,xscl)... ), it's drawing the line that I'm stuck on. How would I get a line out of: X = Xmin + B(Xmax - Xmin) / 10 , Y = Ymax - A(Ymax - Ymin) / 10 ?

A 9x9 slope field would be a bit too small, I think. In fact, I made a part of the program that sets the window variables, does the for() loops based on them (i.e. for(A,xmin,xmax,xscl)... ), it's drawing the line that I'm stuck on. How would I get a line out of: X = Xmin + B(Xmax - Xmin) / 10 , Y = Ymax - A(Ymax - Ymin) / 10 ?

Oh, I'm not talking about a 9x9 slope, but rather a 9 lines across by 9 lines down the entire screen.

A 9x9 slope field would be a bit too small, I think. In fact, I made a part of the program that sets the window variables, does the for() loops based on them (i.e. for(A,xmin,xmax,xscl)... ), it's drawing the line that I'm stuck on. How would I get a line out of: X = Xmin + B(Xmax - Xmin) / 10 , Y = Ymax - A(Ymax - Ymin) / 10 ?

Well what I was kind of saying is that the first For( gives you the x-value. This would check for the slope. Then after you establish what m and x from y=mx+b you would use the second For( loop to establish b. For graphing the line you could then do something similar to adding a half to the x-value in both ways to get a line for the field. I hope that made sense.

Last edited by Guest on 01 Jul 2010 09:31:14 am; edited 1 time in total

Ok. So this program is no where near perfect, I just don't have time to go though it and pick the bugs out. This is what I did though to accomplish a slope field effect. When I fix it I'll post the edit up.

Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.