Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: Example: Section 5.2 (page 41), Plotting 2D Functions

  1. #11
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,865
    Rep Power
    405

    Re: Example: Section 5.2 (page 41), Plotting 2D Functions

    On page 44, exercise 2... how would you write a program to find the roots. I did a search on the web for what a root is, its been many decades since any math for me in school, so I totally forgot how to do these. I read you solve the equation for it equaling zero, but none of the descriptions made sense to me in how they were factoring the equation.

    Here is what I looked at:
    http://www.intmath.com/Equations-of-...tors-Roots.php

    I am lost when I read this:
    The cubic polynomial f(x) = 4x3 − 3x2 − 25x − 6 has degree 3 (since the highest power of x that appears is 3).

    This polynomial can be factored (using Scientific Notebook or similar software) and written as

    4x3 − 3x2 − 25x − 6 = (x − 3)(4x + 1)(x + 2)

    So we see that a 3rd degree polynomial has 3 roots.

    The associated polynomial equation is formed by setting the polynomial equal to zero:

    f(x) = 4x3 − 3x2 − 25x − 6 = 0

    In factored form, this is:

    (x − 3)(4x + 1)(x + 2) = 0 How in the world did they get this from the line above? And how would you even code something to do that?
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  2. #12
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,865
    Rep Power
    405

    Re: Example: Section 5.2 (page 41), Plotting 2D Functions

    I still don't understand the description I put above.

    But in reading more sites, I think I got the idea somewhat.
    So example 1a: y = x2 - 2

    A root is a solution to a problem. It is when the equation evaluates to zero.

    So y = x2 - 2 we subtract y from both sides:
    y-y = x2 -2 -y this then becomes 0 = x2 -2 -y
    So this last equation is the solution.

    Now what, do you just put values in and see which ones work?
    Just sort of guessing, I came up with:
    x=2 , y =2 : x^2 -2 -y : 2^2 -2 -2 : 4 - 2 - 2 : 2 - 2 = 0

    I guess this becomes the brute force method


    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  3. #13
    Member sblank's Avatar
    Join Date
    Feb 2010
    Location
    Wayne City, Illinois
    Posts
    80
    Rep Power
    23

    Re: Example: Section 5.2 (page 41), Plotting 2D Functions

    Hi Kent,

    You are correct that a root is when the value of the function, f(x) = 0. That would occur when the function crosses the x axis. For linear functions, the solution is relatively easy (as long as the function is not parallel to the x axis). For quadratic functions, the quadratic formula works well. For higher order functions, things get a bit more complicated and although there exists a cubic formula, it's fairly complicated. You can use Calculus and Newton's Method for a numeric solution and there are other tricks of the trade...

    But what I usually suggest to my students is to graph the function and have the code look for a change in sign. When a function goes from + to - or - to +, it has crossed the x axis and real root exists nearby. This won't find complex roots, but it will approximate real roots. The smaller the step increment, the more closely you can approximate the root... I even had a student write a program that when it found a sign change, it kept going back and forth, decreasing the interval between sign changes, until it found the root to the precision of the declared variable type.

    Does that help any?

    Cheers,

    Stan

    Quote Originally Posted by kent sarikaya
    I still don't understand the description I put above.

    But in reading more sites, I think I got the idea somewhat.
    So example 1a: y = x2 - 2

    A root is a solution to a problem. It is when the equation evaluates to zero.

    So y = x2 - 2 we subtract y from both sides:
    y-y = x2 -2 -y this then becomes 0 = x2 -2 -y
    So this last equation is the solution.

    Now what, do you just put values in and see which ones work?
    Just sort of guessing, I came up with:
    x=2 , y =2 : x^2 -2 -y : 2^2 -2 -2 : 4 - 2 - 2 : 2 - 2 = 0

    I guess this becomes the brute force method



  4. #14
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,865
    Rep Power
    405

    Re: Example: Section 5.2 (page 41), Plotting 2D Functions

    Thanks Stan for further explanation. Perhaps as I go through the book a light bulb will light up, still in the dark, but at least I got an idea that if we see a plot cross the X axis, that means a root exists.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  5. #15
    Member sblank's Avatar
    Join Date
    Feb 2010
    Location
    Wayne City, Illinois
    Posts
    80
    Rep Power
    23

    Re: Example: Section 5.2 (page 41), Plotting 2D Functions

    That's the idea, Kent. The power of the function tells us how many roots the equation has. If x^5 is the largest power, then there are 5 roots. However, some of these roots may not be real roots... in that case, the function would not cross the x axis at those roots. Only if the function crosses the x axis will we have a real root.

    Later in the text we'll create a graph (using Eros's iComplex library) for the function f(x) = x^3 - 1 and we'll find the roots of this function using Newton's Method and the complex plane. The function has only one real root, but it also has two complex roots and using Eros's library, we can visualize them. It's really neat AND pleasing to the eye AND it's a fractal (and I have to learn how to write the script in ThinBasic).

    Cheers,

    Stan

    Quote Originally Posted by kent sarikaya
    Thanks Stan for further explanation. Perhaps as I go through the book a light bulb will light up, still in the dark, but at least I got an idea that if we see a plot cross the X axis, that means a root exists.

  6. #16
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,865
    Rep Power
    405

    Re: Example: Section 5.2 (page 41), Plotting 2D Functions

    Looking forward to your example Stan. Have fun learning thinBasic. I am still learning each day. Petr helped me with a tough problem I ran into last night. Hopefully now I can finish the program for posting soon.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  7. #17
    Member sblank's Avatar
    Join Date
    Feb 2010
    Location
    Wayne City, Illinois
    Posts
    80
    Rep Power
    23

    Re: Example: Section 5.2 (page 41), Plotting 2D Functions

    I'm trying... I have yet to shed my Python and FreeBasic thinking, but I'm working on it!

    I want to use the new iComplex module Eros added... I'm going to spend time tonight working on something.

    Cheers,

    Stan

    Quote Originally Posted by kent sarikaya
    Looking forward to your example Stan. Have fun learning thinBasic. I am still learning each day. Petr helped me with a tough problem I ran into last night. Hopefully now I can finish the program for posting soon.

  8. #18
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,865
    Rep Power
    405

    Re: Example: Section 5.2 (page 41), Plotting 2D Functions

    Great, good luck!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  9. #19
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,865
    Rep Power
    405

    Re: Example: Section 5.2 (page 41), Plotting 2D Functions

    If you copy and paste equations from Stan's book into the plotter, there is something in pdf that puts in a strange character for " - ", it looks like |, but thicker in the pasted version. Just erase the strange character and re-enter " - " without the quotes. This so far only seems to happen with " - " and not with " + ".
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Example: Section 5.2 (page 38/39), Plot Point, Diagonale + mirror 2D Functions
    By Lionheart008 in forum ThinBASIC programming in OpenGL/TBGL
    Replies: 5
    Last Post: 27-02-2010, 05:28

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •