Finding roots of arbitrary equation in one variable.

Post Reply
Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Finding roots of arbitrary equation in one variable.

Post by Henko »

Code: Select all

' Finding a solution of an arbitrary equation.
' Solution method is the Newton-Raphson iteration.
' In the call statement the parameters are:
'   a starting value for the variable x (here 1.37)
'   the desired precision (here .0000001)
' The algoritm does not converge to a solution for every equation
' and for every starting value, but in most cases it will converge
' to a solution and will do so very fast.
' If the algoritm does not converge to a solution, a result of
' -999 is returned; you can test on this value in the calling
' program.
' If an equation has multiple roots, only one of them will be found
' at one time. If you have some knowledge about the region where the 
' desired solution is, then give a starting value somewhere in that
' region.
' You may enter any formula in the def y(x) function after the =
' sign.
'
'    test program for Newton-Raphson iteration
'
result=solve(1.37,.0000001)
print result
end

def y(x) = x^3-5*sin(x)*exp(-2*x)-5

def solve(xo,eps)
x=xo ! count=0 ! maxcount=100
do
  y_acc=(y(x)-y(x-.01))/.01
  dx=y(x)/y_acc ! x=x-dx ! count=count+1
  until abs(dx)<eps or count=maxcount
if count<maxcount then solve=x else solve=-999
end def

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Finding roots of arbitrary equation in one variable.

Post by Dutchman »

Dag Henk,
Een gelukkig nieuw jaar toegewenst.
I have the impression that you have a math background, therefore the following question.
Have you any idea how we could generate 3D-fractals as in the following picture from: http://apod.nasa.gov/apod/ap131230.html
Attachments
3D-fractal from http://apod.nasa.gov/apod/ap131230.html
3D-fractal from http://apod.nasa.gov/apod/ap131230.html
3D-fractal.jpg (105.7 KiB) Viewed 2559 times

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Finding roots of arbitrary equation in one variable.

Post by Henko »

Dutchman wrote:Dag Henk,
Een gelukkig nieuw jaar toegewenst.
I have the impression that you have a math background, therefore the following question.
Have you any idea how we could generate 3D-fractals as in the following picture from: http://apod.nasa.gov/apod/ap131230.html
Hi, Dutchman,
A nice 2014 to you and to the other fellows as well.
I'm not a mathematician, but an HTS engineer and used math a lot in my working period, but the math level is restricted.
As for the 3D fractals (a very nice picture!), I suppose that you would use the "quaternion" number system for that, which is a generalization of the complex number system (google for "quaternionen" in the Dutch wikipedia). They are not yet a standard data type in Smart Basic :-). I guess that the fractal calculations using the quaternion numbers follow much the same scheme as for 2D fractals. Presenting the 3D results on a screen is another story, but the picture shows a very nice way to do so.

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Finding roots of arbitrary equation in one variable.

Post by Dutchman »

That's a pity. I have the same eduction and had my career in electronic design.
On the website where the picture was published http://apod.nasa.gov/apod/ap131230.html there is a link to "Mandelbulb' http://en.wikipedia.org/wiki/Mandelbulb where it is indicated that it is done withoutn quaternions.
I think that I will have a try.

Post Reply