TI-89 HomeGames ArchiveTitanium GamesGames How ToProgramsFAQForumTI-89 WikiLinks

More working with multiple answers

 
Post new topic   Reply to topic    Your TI-89 Resource Forum Index -> BASIC Programming
Author Message
sisseck



Joined: 31 Oct 2007
Posts: 2

PostPosted: October 31, 2007 4:32 AM    Post subject: More working with multiple answers Reply with quote

Hi i just read the topic about multiple answers and the part() command works great. But i am working on a program where the solve() function gives multiple x and y values. The really tricky part is that the number of solutions are not constant. Anyone know how to get around this problem?
Back to top
View user's profile Send private message
mellamokb



Joined: 10 May 2007
Posts: 100

PostPosted: October 31, 2007 10:00 AM    Post subject: Reply with quote

Hi sisseck,

Welcome to TI-89.org forums.

It's really hard to help you with your problem without some sort of example to go off of. There are very many ways to parse information if you have criteria. For instance, you could use the "part(" function in a loop to continuously retrieve values of x and y until a certain criteria is met, like the part function returns a number instead of an equation. If you could give a concrete example portraying the complexity of your equations you are solving, then I could suggest some better possibilities for you.

Hope this helps!

~ mellamokb
Back to top
View user's profile Send private message
sisseck



Joined: 31 Oct 2007
Posts: 2

PostPosted: October 31, 2007 1:10 PM    Post subject: min max and saddelpoints Reply with quote

The equations im working on are 3d grafs z(x,y)=x^4+16xy+y^4 for instance. up till now the program i have written can hande it as long as there is only 1 max. min. or saddel point. I'm pretty sure that the part command will do the trick, but still need to figure the finer points of the programming out.
Back to top
View user's profile Send private message
mellamokb



Joined: 10 May 2007
Posts: 100

PostPosted: November 5, 2007 11:34 AM    Post subject: Reply with quote

sisseck,

Here is an example of what I meant in my previous post. Suppose you solved an equation and got the following result:

Code:

x=5 and y=19 or x=3 and y=22 or x=6 and y=10



Clearly, there are three solutions to x and y that you want out of this expression. Also, actual solutions are separated by the word "or". If you use the part function on this expression, it will separate pieces around the word "or", which is pretty convenient:

Code:

part(x=5 and y=19 or x=3 and y=22 or x=6 and y=10, 0)
"or"
part(x=5 and y=19 or x=3 and y=22 or x=6 and y=10, 1)
x=5 and y=19
part(x=5 and y=19 or x=3 and y=22 or x=6 and y=10, 2)
x=3 and y=22 or x=6 and y=10



So a short function to get all the solutions and return them as a 2xn matrix might go something like this (assuming the solution expression like "x=5 and y=19 or x=3 and y=22 or x=6 and y=10" is passed as the argument, e):

Code:

parsesol(e)
Func

Local i,s,lx,ly
NewList(1)->lx
NewList(1)->ly
1->i

While part(e,0)="or"

part(e,1)->s
part(e,2)->e

part(part(s,1),2)->lx[i]
part(part(s,2),2)->ly[i]

i+1->i

EndWhile

part(part(e,1),2)->lx[i]
part(part(e,2),2)->ly[i]
Return {lx,ly}

EndFunc



Example usage:

Code:

parsesol(x=5 and y=19 or x=3 and y=22 or x=6 and y=10)
[[3,5,6][22,19,10]]



You should be able to get the general idea from the function I've written. You could also use a program if you wanted instead of a function (programs allow input/output, functions don't, but can return values to the home screen, unlike programs). You should be able to fine-tune the idea using different comparisons and combinations of the part( function for your particular situation.

Another interesting built-in function you might look at is the zeros( function, which will find all zeros of an expression and return them as a list rather than "x=5 or x=6 or x=7 or ...", which might be easier to work with. Here is an example usage to compare the two:

Code:

Solve(x^3-7x=-6,x)
x=-3 or x=1 or x=2
Zeros(x^3-7x+6,x)
{-3,1,2}



Hope this helps!

~ mellamokb
Back to top
View user's profile Send private message
Display posts from previous:    View previous topic : View next topic  
Post new topic   Reply to topic    Your TI-89 Resource Forum Index -> BASIC Programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Contact Us | Privacy Policy | Disclaimer | Trademarks

Copyright ©2006 All rights reserved.


Free Greeting Cards | Girly Myspace Layouts | Myspace Unblocker |