Jump to content



Photo

Cplua Project:lua Graph Library


  • Please log in to reply
26 replies to this topic

#1 Kilburn

Kilburn

    Casio Technician

  • Members
  • PipPipPipPipPipPip
  • 491 posts
  • Gender:Male
  • Location:France
  • Interests:Blah

  • Calculators:
    FX-7500 G
    ClassPad 300

Posted 05 October 2005 - 06:12 PM

I have made a Graph library similar than LuaPlot: Lua Graph Library 1.00

Posted Image

Here are the actual functions:

* graph.show()  Shows the graph window
* graph.refresh()  Clears the graph window and retraces the axes and the grid
* graph.setaxes(set)  set=1:Enable axes | set=0:Disable axes
* graph.setgrid(set) set=0:Disable grid | set=1:Enable grid (points) | set=2:Enable grid (dotted lines)
* graph.viewwindow(xmin,xmax,xscl,ymin,ymax,yscl) Sets the window settings
* graph.plot(x,y) Draws a point in graphical coordinates
* graph.line(x1,y1,x2,y2) Draws a line in graphical coordinates
* graph.splot(x,y,type) Draws a special point. Reserved for stat graphs
* graph.vmesh(x) Draws a vertical dotted line
* graph.hmesh(y) Draws an horizontal dotted line
* graph.update() = draw.update()

* graph.drawfunc(func[,line=THIN,min=xmin,max=xmax,show=NORMAL]) Draws a "y(x)=" function
  line=PLOT, THIN or THICK : Type of line
  min,max : Lower and upper X boundaries.
  show=NORMAL : Trace a graph as on the Graph application
  show=SHOWBUFFER : Shows the graph only when the tracing finishes
  show=KEEPBUFFER   : Don't show the graph. You must call graph.update() to show it.

* graph.drawinv(func[,line=THIN,min=ymin,max=ymax,show=NORMAL]) Draws a "x(y)=" function
  min,max : Lower and upper Y boundaries.

* graph.drawpol(func,min,max,step[,line=THIN,show=NORMAL]) Draw a "r(th?ta)=" function
  min,max,step : Start angle, end angle, angle pitch.
  line,show : Explained in the previous functions.

* graph.drawparam(func,min,max,step[,line=THIN,show=NORMAL]) Draw a "x(t),y(t)=" function
  min,max,step : Start T, end T, T pitch.
   Important:Declare the function as below:
	function f1(t)
	 (what you want...)
	 return x,y
	end

* graph.drawstat2v(xdata,ydata[,point=DOT,line=THIN,show=NORMAL]) Draws a simple two-variable graph
  xdata,ydata : Lists used to trace the graph
  point : Point type : DOT : dot | LDOT : large dot | SQUARE : square | CROSS : cross | CIRCLE : circle | CIRCLE2 : circle with a cross inside of it
  line : Line type : PLOT,THIN,THICK

* graph.plotfunc(f,table[,point,line,show]) Draws a function using a table.
  table : X Values

* gTbl(start,end,step) Generates a table to use in graph.plotfunc()

If you have suggestions or bug reports, please post them on this topic.

#2 Kilburn

Kilburn

    Casio Technician

  • Members
  • PipPipPipPipPipPip
  • 491 posts
  • Gender:Male
  • Location:France
  • Interests:Blah

  • Calculators:
    FX-7500 G
    ClassPad 300

Posted 09 October 2005 - 08:40 AM

I am actually working on a new version. I'll include statistics regressions. I managed to add linear regressions, but I don't know the algorithms of the others (like quadratic,logistic,sinuso?dal).

If somebody reads this topic (which is not active at all!), please help me! :cry:

#3 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 09 October 2005 - 09:16 AM

Sorry I don't know those algorithms neither :(

#4 rafapa

rafapa

    Newbie

  • Members
  • Pip
  • 14 posts
  • Location:Spain

Posted 09 October 2005 - 08:07 PM

I am actually working on a new version. I'll include statistics regressions. I managed to add linear regressions, but I don't know the algorithms of the others (like quadratic,logistic,sinuso?dal).

If somebody reads this topic (which is not active at all!), please help me! :cry:


You can try www.nr.com (Numerical Recipes). There is a lot of information about numerical methods. Chapter 15 of "Numerical Recipes in C++" deals with your question. There are versions in other languages.

Cheers,

Rafael

#5 unique33

unique33

    Casio Freak

  • Possibly hacked
  • PipPipPipPip
  • 229 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    classpad 300 , fx5500

Posted 27 October 2005 - 11:41 PM

there is a capability in maple to draw a function from - infinity to infinity
plot({exp,ln}, -infinity .. infinity ) ;
Posted Image

can this be added ?

#6 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 28 October 2005 - 07:51 AM

I am actually working on a new version. I'll include statistics regressions. I managed to add linear regressions, but I don't know the algorithms of the others (like quadratic,logistic,sinuso?dal).
If somebody reads this topic (which is not active at all!), please help me! :cry:

I think that implementing statistics regressions graphically is not the best way to proceed. It's actually the way that ClassPad OS uses, and it's not convenient at all, at least in my opinion. In ClassPad, one should do the regression graphically, and the resulting function can be obtained by accessing system variables; is this the best way to implement regressions? I think that it is not. I'm thinking of Lua functions that implement, e.g., exponential or logarithmic regression and return the resulting function. This function can then be used in other calculations, and, of course, it can also be plotted by simple function plotting commands. I'm planning to implement statistics regressions in LuaNumAn this way. However, this has a rather low priority for me, since there other, more important (and more challenging) numerical methods that should be implemented first, such as Cubic Splines, solving systems of non-linear equations, solving boundary value problems etc. In other words, you shouldn't expect LuaNumAn to support statistics regressions soon. However, if regressions are so popular, and several users consider it so important, I may change my mind, and implement it sooner than I'm planning. Unfortunately, the LuaNumAn topic is not very active, so, for now, I don't see any reason to change my plans.

In any case, my opinion is: do not implement statistics regressions in your Graph library, because they are not plotting functions, they are numerical methods. Instead, try to make the library more robust and efficient. For example, try to implement logarithmic or semi-logarithmic plots (an idea that is still in my list for the LuaPlot library as well).

there is a capability in maple to draw a function from - infinity to infinity
plot({exp,ln}, -infinity .. infinity ) ;
can this be added ?

I think that it can. One should use cas.limit to find the limits of the function in -infinity and +infinity for this. However, I don't see a way to make it robust, and, to be honest, I don't see a good reason to add such a capability in a plotting library. :unsure:

#7 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 28 October 2005 - 08:55 AM

Unfortunately, the LuaNumAn topic is not very active

I just wanted to say that this is mainly due to the "non public" state of the CPLua project, thus there are certainly many persons that would be interested in it but they simply don't know that your library exists :rolleyes:
However I'd like to warn you again that deep changes are allways possible before the official release of CPLua 1.0, so if you work on a big project now it could be necessary to perform many adaptations between the different versions ;) (I do not plan to change the user's side too much, but I realize that everything is changing inside CPLua and I still don't know if it will have many consequences on its use :unsure: )

#8 rafapa

rafapa

    Newbie

  • Members
  • Pip
  • 14 posts
  • Location:Spain

Posted 28 October 2005 - 10:41 AM

I just wanted to say that this is mainly due to the "non public" state of the CPLua project, thus there are certainly many persons that would be interested in it but they simply don't know that your library exists :rolleyes:
However I'd like to warn you again that deep changes are allways possible before the official release of CPLua 1.0, so if you work on a big project now it could be necessary to perform many adaptations between the different versions ;) (I do not plan to change the user's side too much, but I realize that everything is changing inside CPLua and I still don't know if it will have many consequences on its use :unsure: )


Dear Orwell,
by "everything is changing inside CPLua" you also means Lua version? I believe that 5.1 (final) is going to be released any day. Just a curiosity, to include a new Lua version inside CPLua it's a difficult task?

Best regards

#9 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 28 October 2005 - 12:12 PM

No, I'm not planning to change the version of Lua itselfs. I'm just reorganizing the add-in and the libraries, I won't change anything in the Lua kernel. For example, I'm going to change the way I manage the windows (console & graph) during the execution of a script, so it will be quite easier to create a new kind of window that would be specific to a certain library etc :)
Since the Lua kernel is left intact, it shouldn't be too difficult to replace it by a new version ;)

#10 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 28 October 2005 - 12:31 PM

I just wanted to say that this is mainly due to the "non public" state of the CPLua project, thus there are certainly many persons that would be interested in it but they simply don't know that your library exists :rolleyes:

Hmmm, wish you are right, but I'm afraid that this is not the reason. Afterall, CPLua is a public project, in the sense that anyone can use it right now to write something useful. The source coude is not public, but I don't think that most ClassPad users will ever need it. If you ask me, I think that the real reason is that most users are simply not interested in Numerical Analysis, or they are waiting for an official CPLua release, letting us to do the "dirty job" in the meantime (developing and debugging).

However I'd like to warn you again that deep changes are allways possible before the official release of CPLua 1.0, so if you work on a big project now it could be necessary to perform many adaptations between the different versions ;) (I do not plan to change the user's side too much, but I realize that everything is changing inside CPLua and I still don't know if it will have many consequences on its use :unsure: )

I know, I know, you have already warned me about that (and you do well). However, I will take the risk :greengrin:, and I will never say that I haven't been warned. Afterall, developing such a "big" project before the CPLua official release is very useful for debugging purposes, isn't it?

#11 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 28 October 2005 - 01:05 PM

Afterall, developing such a "big" project before the CPLua official release is very useful for debugging purposes, isn't it?

Of course it is ;)

#12 unique33

unique33

    Casio Freak

  • Possibly hacked
  • PipPipPipPip
  • 229 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    classpad 300 , fx5500

Posted 28 October 2005 - 09:40 PM

I think that it can. One should use cas.limit to find the limits of the function in -infinity and +infinity for this. However, I don't see a way to make it robust, and, to be honest, I don't see a good reason to add such a capability in a plotting library. :unsure:


try this:
solve(ln(x)=exp(x),x)
classpad can not solve this equation
but if you draw the equations you will see If there is an answer or not .

also consider this (for students of precalculus )(for example for students of preuniversity ,
as you know they do not have a good view point about the limit) :

lim(sin(x),x,+infinity)

you can easily show him why there is no limit .
also there are other situation where it can be useful.

#13 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 29 October 2005 - 08:20 AM

try this:

solve(ln(x)=exp(x),x)
classpad can not solve this equation
but if you draw the equations you will see If there is an answer or not .

Yes, ClassPad CAS cannot solve this equation analytically, but you can easily solve it numerically, by using, e.g., the "NumSolve" application, or my LuaNumAn library functions (Bisect, Brent, or KroneRoots) <_<. In both cases, one can easily find that there is no solution in this particular case.

also consider this (for students of precalculus )(for example for students of preuniversity ,
as you know they do not have a good view point about the limit) :

lim(sin(x),x,+infinity)
you can easily show him why there is no limit .
also there are other situation where it can be useful.

Well, isn't obvious that this limit does not exist? But even if it's not, is it necessary to plot it from -infinity to +infinity to show this? Wouldn't be easier to plot it from, say, -100 to 100, then aumenting the plotting interval?
In any case, plotting from -infinity to +infinity is unsafe, since, mathematically, it does't make sense. Maple has such a capability, but I think that one can find "pathological" cases, where this feature doesn't work as it should. I'm not exactly sure, but, if I have to bet for this, I will surely bet that plotting from -infinity to infinity cannot implemented in a robust way.

#14 unique33

unique33

    Casio Freak

  • Possibly hacked
  • PipPipPipPip
  • 229 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    classpad 300 , fx5500

Posted 02 November 2005 - 09:07 PM

In any case, plotting from -infinity to +infinity is unsafe, since, mathematically, it does't make sense. Maple has such a capability, but I think that one can find "pathological" cases, where this feature doesn't work as it should. I'm not exactly sure, but, if I have to bet for this, I will surely bet that plotting from -infinity to infinity cannot implemented in a robust way.


here is the maple description about plot[infinity]

. If either of the range end points of the horizontal range contains +-infinity,
an infinity plot is generated.

. An infinity plot is obtained by transforming -infinity .. infinity to -1 .. 1 by a transformation
that approximates arctan. This is a nice way of getting the entire picture of f(x) on the display.
Such a graph, although distorted near x = -infinity and infinity, contains a lot of information
about the features of f(x).

#15 Kilburn

Kilburn

    Casio Technician

  • Members
  • PipPipPipPipPipPip
  • 491 posts
  • Gender:Male
  • Location:France
  • Interests:Blah

  • Calculators:
    FX-7500 G
    ClassPad 300

Posted 03 November 2005 - 07:33 PM

. An infinity plot is obtained by transforming -infinity .. infinity to -1 .. 1 by a transformation
that approximates arctan. This is a nice way of getting the entire picture of f(x) on the display.
Such a graph, although distorted near x = -infinity and infinity, contains a lot of information
about the features of f(x).


Interesting... Could you more precise?
I started a gsolve package, which uses the cas functions. Is it possible to extract an element from a cas list?
example: cas.fmin("x^2+1","x") -> "{x=0, MinValue=1}"
How can I get only "MinValue=1" ?

I'm thinking of Lua functions that implement, e.g., exponential or logarithmic regression and return the resulting function. This function can then be used in other calculations, and, of course, it can also be plotted by simple function plotting commands. I'm planning to implement statistics regressions in LuaNumAn this way.


Exactly what I wanted to do. :thumbsup:

#16 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 03 November 2005 - 09:55 PM

I started a gsolve package, which uses the cas functions.

I just want to say that solving equations is already implemented in LuaNumAn. There are three functions available for this, and I think that they are more powerful than any graphical solution, similar to gsolve. Graphical solvers are by nature less precise than pure numerical methods, and they are useful only for a raw approximation.

Exactly what I wanted to do. :thumbsup:

Linear, exponential or logarithmic regressions can be very easily implemented, but a robust implementation is not trivial: it needs an automated way to decide which regression best fits the data, and an estimation of the "chi squared", together with estimations of error tolerances in all parameters of the fitting curve. However, LuaNumAn already includes a non-linear fitting function LMFit, which is able to fit data to any theoretical curve; this fitting curve may depend on many parameters. LMFit also returns error estimations for all the parameters computed. In other words, LMFit is able to do much more things than simple regressions. The only drawback is that LMFit is much more complex than simple regressions; but for the end-user, there is no serious difference. Conclusion: You can already do simple regressions: you can also plot them (with LuaPlot or your Graph library), and you can use the results in your programs. That is the reason that I'm not planning to add logarithmic or exponential regressions soon: they are already implemented, in a more general and powerful way :greengrin:.

#17 unique33

unique33

    Casio Freak

  • Possibly hacked
  • PipPipPipPip
  • 229 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    classpad 300 , fx5500

Posted 04 November 2005 - 02:45 AM

using PAP krone program to find the roots of :
8*cos(x)-x

Posted Image

If you set the xlim={-40,40} you can not get the answers .
but If you plot it from -infinity to infinity you can see that there is 5 roots
so we should change the xlim to get the answer
say xlim={-40,0} no answer
say xlim={-40,-1}
we will get
-4.164830914061
-1.7974066800187

then we will set the xlim to positive values :
xlim={0,40}
then we will get the positive answers :

1.3954661438719
5.4643028307947
6.8306743262038

also consider this
(1/x^4)-3+x^2
Posted Image

from the graph we now that there is 4 answers

if we set the xlim to {-12,0} we can not get the answers
then we try {-12,.5}
we will get :
-1.6968751402422
-.80790076412028

now the positives:
xlim={0,12} no answer
xlim= {.1,10} no answer
try {.1,5}
answers:
.80790076412028
1.6968751402422

maybe someone say that we can plot the function from say -500 to 500 to see if there is roots or no
but (500-(-500))/infinity -> ?

however it is just a suggestion.

#18 Kilburn

Kilburn

    Casio Technician

  • Members
  • PipPipPipPipPipPip
  • 491 posts
  • Gender:Male
  • Location:France
  • Interests:Blah

  • Calculators:
    FX-7500 G
    ClassPad 300

Posted 04 November 2005 - 11:12 AM

I understood nothing... :huh:

#19 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 04 November 2005 - 12:31 PM

using PAP krone program to find the roots of :

8*cos(x)-x
.....

Well, you are using KroneRoots improperly, or to be more precise, without reading the documentation first. The behavior you reported is not actually a bug, it's a typical example of improper function call :greengrin:. You get different results for different search intervals simply because the crucial parameter xi of KroneRoots is not changed as it should. Please read the documentation about this, and change your program accordingly. You will see that everything will be correct, if you use KroneRoots correctly :greengrin:.
If you have already tried to call KroneRoots with the optional argument xi included, but you still have problems, I can post here the correct Lua code for your examples, together with further explanations. But, before this, try to change xi as documented, if you didn't it already.

PS: First of all, you should realize that Numerical Analysis is not magic ;).
----------------------------------

I understood nothing... :huh:

Hmmm, you are too young for Mathematical Analysis, aren't you?

#20 Kilburn

Kilburn

    Casio Technician

  • Members
  • PipPipPipPipPipPip
  • 491 posts
  • Gender:Male
  • Location:France
  • Interests:Blah

  • Calculators:
    FX-7500 G
    ClassPad 300

Posted 04 November 2005 - 01:53 PM

Hmmm, you are too young for Mathematical Analysis, aren't you?


I'm 14... why? :roflol:

#21 unique33

unique33

    Casio Freak

  • Possibly hacked
  • PipPipPipPip
  • 229 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    classpad 300 , fx5500

Posted 04 November 2005 - 02:24 PM

Well, you are using KroneRoots improperly, or to be more precise, without reading the documentation first. The behavior you reported is not actually a bug, it's a typical example of improper function call :greengrin:. You get different results for different search intervals simply because the crucial parameter xi of KroneRoots is not changed as it should. Please read the documentation about this, and change your program accordingly. You will see that everything will be correct, if you use KroneRoots correctly :greengrin:.
If you have already tried to call KroneRoots with the optional argument xi included, but you still have problems, I can post here the correct Lua code for your examples, together with further explanations. But, before this, try to change xi as documented, if you didn't it already.


yes , you are totally right.
I did not want to report a bug . just to show an example .
I,m sorry If I bothered you.
I just want to show that If some one want to get all of the roots of a function then
by infinity plot we can see If there are roots other than the interval we have choosed or not.
maybe someone choose {-1000,1000} with a proper xi and get plenty of roots ( or all the roots within the interval ) but he can not be sure that there are no other roots ...
If you have a good example for such a function let us know.

PS: First of all, you should realize that Numerical Analysis is not magic ;).


yeah. you are right as always .

#22 Kilburn

Kilburn

    Casio Technician

  • Members
  • PipPipPipPipPipPip
  • 491 posts
  • Gender:Male
  • Location:France
  • Interests:Blah

  • Calculators:
    FX-7500 G
    ClassPad 300

Posted 04 November 2005 - 02:50 PM

can you explain me more precisely ho to plot a function from -inf to +inf?
(I am 14, so... it will be difficult)

#23 unique33

unique33

    Casio Freak

  • Possibly hacked
  • PipPipPipPip
  • 229 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    classpad 300 , fx5500

Posted 04 November 2005 - 09:37 PM

can you explain me more precisely ho to plot a function from -inf to +inf?
(I am 14, so... it will be difficult)


ok
use this function

arctan(f(x)|x=tan(x))
plot it for x=-pi/2..pi/2 (or x=(-pi/2+.001)..(pi/2-.001))
y=-pi/2..pi/2

be sure the Angle is in Radian .

here is the infinity plot for
tan-1((x^2/(x^3+2))|x=tan(x))
Posted Image


tan-1(x^2|x=tan(x))
Posted Image


tan-1((8*cos(x)-x)|x=tan(x))
Posted Image


tan-1(tan(x)|x=tan(x))
Posted Image


tan-1(sqrt(abs(x))|x=tan(x))
tan-1(x^2|x=tan(x))
tan-1((-sqrt(.5-x^2)-.5)|x=tan(x))
Posted Image

-------------------------------------------------------------------------------------
but as you can see we should work more to have better result in infinity.

#24 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 05 November 2005 - 10:55 AM

I,m sorry If I bothered you.
I just want to show that If some one want to get all of the roots of a function then
by infinity plot we can see If there are roots other than the interval we have choosed or not.
maybe someone choose {-1000,1000} with a proper xi and get plenty of roots ( or all the roots within the interval ) but he can not be sure that there are no other roots ...
If you have a good example for such a function let us know.

Maybe I was misunderstood. You didn't bothered me at all!

Now, about your remarks: Indeed, you cannot use KroneRoots to compute all the roots of a function from -infinity to +infinity. As far as I know, there is no way to do this. However, you can plot the function in order to choose an interval large enough, so that it contains all the roots, then you can use KroneRoots to compute them without any problem. Be sure to use a proper xi value. Here are some practical guidelines to find a proper value for xi: this quantity must be set so that f'(x)/f(x) is not too small or too large, compared to unity. In most cases, you can take xi~=max(|f'(x)|)/max(|f(x)|). For example, let's examine the functions you have tried, without success:

Roots of 8*cos(x)-x in the interval {-40,40}
Here, df/dx=-8*sin(x)-1. Now, roughly speaking, max(|f(x)|)~=8+40=48, and max(|f'(x)|)~=8+1=9. Therefore, the value for xi must be something like 9/48. Indeed, if you try
KroneRoots(f,dfdx,d2fdx2,-40,40,0,9/48)
you get the correct result (5 roots). You failed to compute the roots because you used xi=1, which is about two times the correct value ;).
Note that max(|f'(x)|) and max(|f(x)|) can also be computed roughly by plotting f(x) and df/dx. You can also use the CAS function fMax, which is very powerful:
fMax(8*cos(x)-x,x,-40,40)
yields 45.76, and
fMax(-8*sin(x)-1,x,-40,40)
yields 9. Therefore, using fMax we get xi=9/45.76. But there is no need to use fMax: even the rough estimation, xi=9/48, is ok.

Roots of (1/x^4)-3+x^2 in the interval {-12,12}
Here, df/dx=-4/x^5+2*x. But you should be careful: this function goes to infinity as approaches zero! You cannot use KroneRoots in the interval {-12,12}! So, let's seek for the roots in {-12,-0.5}. Here, roughly speaking, the terms 1/x^4 and 1/x^5 are too small in the majority of the interval, so that max(|f(x)|)~=-3+12^2=141, and max(|f'(x)|)~=2*12=24. Therefore, the value for xi must be something like 24/141. Indeed,
KroneRoots(f,dfdx,d2fdx2,-12,-0.5,0,24/141)
yields 2 roots, and it is totally correct. Similarily, use
KroneRoots(f,dfdx,d2fdx2,0.5,12,0,24/141)
to compute the roots at {0.5,12}.

As you can see, KroneRoots can compute all the roots within a given interval with certainty, provided that you call the function properly, i.e., you use a proper value for xi. You can also see that finding a proper value for xi is not difficult at all. But you must choose xi: Calling KroneRoots blindly may give inaccurate results.

I'm currently away from my home computer, and I cannot post the output (and the graphics) of a Lua program that solves the examples above. I'm planning to post them in a few days. Maybe you can do it for me? You just need to modify DKrone a bit ;).

PS: I have written a version of KroneRoots where xi is choosed automatically, so that the user does not need to be bothered with xi. However, this version is considerably slower, so i decided not to publish it.

#25 Kilburn

Kilburn

    Casio Technician

  • Members
  • PipPipPipPipPipPip
  • 491 posts
  • Gender:Male
  • Location:France
  • Interests:Blah

  • Calculators:
    FX-7500 G
    ClassPad 300

Posted 05 November 2005 - 04:40 PM

Thanks :clap:

#26 unique33

unique33

    Casio Freak

  • Possibly hacked
  • PipPipPipPip
  • 229 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    classpad 300 , fx5500

Posted 08 November 2005 - 10:37 AM

I'm currently away from my home computer, and I cannot post the output (and the graphics) of a Lua program that solves the examples above. I'm planning to post them in a few days. Maybe you can do it for me? You just need to modify DKrone a bit ;).


I,m not at home too. :(

I,m at home just at the weekends ( but not always too).

#27 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 09 November 2005 - 09:11 AM

Here are the results obtained by LuaNumAn, for the functions posted by unique 33:

Posted ImagePosted ImagePosted Image

The first example corresponds to the function 8*cos(x)-x, and the second to the function (1/x^4)-3+x^2. The Lua program that produces these results uses the function KroneRoots with the parameter xi selected as I have explained in my previous post. You can reproduce these graphs by modifying the driver program "DKrone" slightly.

PS: For some reason, KroneRoots seems to be the only "popular" LuaNumAn function. This forced me to recheck its functionality, and to improve its performance (the current version 1.40 is about 2 times faster than version 1.00). I can now guarantee (and I bet my CP for this) that KroneRoots is able to compute all the roots of a given function within a given interval, provided that it is used properly. That means: (1) Select a proper value for xi, as explained in the manual, and in my previous post, (2) There are no discontinuities within the seach interval.


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users