Author Topic: Critical point numbers  (Read 3441 times)

0 Members and 1 Guest are viewing this topic.

Offline Wretchedlout

  • LV3 Member (Next: 100)
  • ***
  • Posts: 64
  • Rating: +6/-0
    • View Profile
Critical point numbers
« on: October 07, 2012, 01:34:52 pm »
Hello there, I wish to create a program that finds the critical point numbers of a formula in Y1. (Critical point numbers are just x values where the derivative (or slope) is 0.) so that requires some equation solving.

Ex:
       4X4-16X2=0
       4X2(X2-4)=0
4X2(X-2)(X+2)=0

X=-2, 0, 2

Is there any way to do that without:
Code: [Select]
For(A,-50,50
if abs(nderiv(Y1,X,A)))<.0001
A->LZ(A+50
End
?

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Critical point numbers
« Reply #1 on: October 07, 2012, 01:44:38 pm »
Take a sheet of paper, find the derivative of the function in Y1 and solve it as an equation to see where it reaches 0. The program you suggested will only work if the x-coordinates of the critical points are integer values between -50 and 50.
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline Wretchedlout

  • LV3 Member (Next: 100)
  • ***
  • Posts: 64
  • Rating: +6/-0
    • View Profile
Re: Critical point numbers
« Reply #2 on: October 07, 2012, 01:57:44 pm »
I understand, is there a way for the calculator to do it very fast with no limits?

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Critical point numbers
« Reply #3 on: October 07, 2012, 02:26:33 pm »
Draw the graph, then do 2ND>CALC and select minimum or maximum, depending on if you want to know the minimum or maximum value of a point. Then, select a point in front of the critical point,  press enter, select a point behind it, then press enter twice. Repeat for every critical point.
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline Wretchedlout

  • LV3 Member (Next: 100)
  • ***
  • Posts: 64
  • Rating: +6/-0
    • View Profile
Re: Critical point numbers
« Reply #4 on: October 07, 2012, 02:35:18 pm »
not using the graph, just a formula to find each very fast

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Critical point numbers
« Reply #5 on: October 07, 2012, 03:01:55 pm »
Ok, so there's no good way to do what you're trying to do.

Firstly, two functions you should know about:
nDeriv(expression, variable, value)
solve(expression, variable, guess)

Now, the way these work, is the first one will take the derivative for you, so nDeriv(x^2,x,2) will give you 4, and nDeriv(x^3,x,y) will behave like 3y^2 (though it will be far slower).

solve( is just the functional way to use solver. expression is what is set equal to zero, so if we want x^2 = 0, we would do solve(x^2,x,1) = 0. The trouble with this is that it will only find one of the zeros, and an example of this is x^2 = 4. If we rearrange that we get x^2 - 4 = 0. So solve(x^2,x,1) = 2 and solve(x^2,x,-1) = -2. But the key is you have to guess correctly for both.

Now, the actual code that does your work is going to look like this: solve(nDeriv(expression,variable,Y), Y, guess). Again, to find the critical point of x^2, you would do solve(nDeriv(x^2,x,y),y,1) and this will spit out 0.


Here's the trouble, that worked great for that equation because it only had one critical point. But if it has two, you need to run it twice with different guesses. I don't know how to detect the number of critical points nor decide where to guess, so that one will be up to you.

The best thing I can say for this would be to quickly graph the derivative and then decide how many critical points you think there are. Something like this might do the trick.

nDeriv(equation,x,x) -> Y1
ZoomFit
2->XRes
Trace
Prompt for number of zeros
Prompt for each guess

For(A,1, number of zeros)
solve(Y1, x, guess[A])
End


Edit:
   Sorry, missed your code example, so my post is a little less relevant, but still works.
« Last Edit: October 07, 2012, 03:02:45 pm by thepenguin77 »
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline Wretchedlout

  • LV3 Member (Next: 100)
  • ***
  • Posts: 64
  • Rating: +6/-0
    • View Profile
Re: Critical point numbers
« Reply #6 on: October 08, 2012, 07:01:03 pm »
well thanks

Offline DrDnar

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 546
  • Rating: +97/-1
    • View Profile
Re: Critical point numbers
« Reply #7 on: October 09, 2012, 12:24:58 am »
I understand, is there a way for the calculator to do it very fast with no limits?
not using the graph, just a formula to find each very fast
If there was, they'd teach it to you in school. Slow, numeric methods and symbolic calculus methods are the only ways of doing it. The symbolic calculus functionality you're looking for is called a CAS (Computer Algebraic System), and it's why you're probably not allowed to use a TI-89 or Nspire-CAS.
"No tools will make a man a skilled workman, or master of defense, nor be of any use to him who has not learned how to handle them, and has never bestowed any attention upon them. . . . Yes, [] the tools which would teach men their own use would be beyond price."—Plato's The Republic, circa 380 BC