On Aug 26, 10:55*am, serave <ramirez.sebast ...@gmail.comwr ote:
On 26 ago, 01:53, cwdjrxyz <spamtr...@cwdj r.infowrote:
On Aug 25, 9:18*pm, serave <ramirez.sebast ...@gmail.comwr ote:
Hi i'm new in this group. I need some help with php. I need to draw
any mathematical function i get through a form?
Do you mean you need to draw a curve from the results of solving an
exact equation or do you mean you need to fit the best curve to a set
of experimental measured points that always have some error. In the
second case, a good bit of statistical calculation often is required.
If you are a glutton for punishment, you can do this with the Math
functions of Javascript or php. You would be much better off using a
language such as c++ or even old Fortran which are better designed for
math and science calculations and curve fitting. There are all sorts
of math programs for curve fitting, plotting, solving equations, etc
and these are what most people now use when working with math. You
will find such programs advertised in many scientific and math
journals. Unfortunately many of these programs are rather expensive
for an individual, but they very soon pay for themselves in time saved
for a company that needs many such math and curve fitting programs and
has to hire many highly trained people with advanced degrees.
I have 2 examples of drawing curves from solution of math equations
at:http://www.cwdjr.net/math/bessel_function2.html
http://www.cwdjr.net/geometricDraw/curve_write.html
This was done using the math functions of Javascript, but the Math
functions of php could have been used. These pages are very old, and I
likely would use different code if doing them today. Now if you wanted
to input experimental points and curve fit to the data, the
calculations become much more complicated because of the statistical
calculations needed to give the curve that best fits the experimental
data. You would input the experimental data into arrays most likely.
No i just need to draw the function, no need to draw the best
aproximation. Is just drawing the curve based on a mathematical
equation like y=e^(x-5)+sin(5x^3)-45x^(2/3) or something like that
Then you solve the equation for say y at closely spaced points of x
using the Math functions of Javascript or php at closely spaced points
of the x coordinate and display each point calculated using a
document.write in Javascript. The structure of code is much the same
in php, but the details are rather different.
In the first example I gave you, the Bessel function of the type given
has no exact solution involving simple math functions. It must be
solved in terms of infinite series, and this is quite tricky and
requires a very good understanding of math that usually is taught at
the college level in courses such as advanced calculus.
The second example I gave you with several curves is much more simple,
as the equation can be solved in terms of known simple functions.
Considering the calculation of the 2 circles, the equations are solved
using JavaScript math and points are written using document.write.
That part of the code is:
var c1=.02,c3=.01 // angle
increment
var px1=270 // center x
var py1=180 // center y
var r1=165,r2=175,r 3=160,r4=185 // radius
var ns1=325,ns3=650 // number of steps
var z=0,y,x ;
for (i=0;i < ns1;++i) {
x = (px1 + r1*Math.cos(z)) ; y= (py1 + r1*Math.sin(z)) ;
document.write( '<div style=\"positio n:absolute; left:'+x+'px; top:'+y
+'px; height:4px; width:4px; background-color: #ff0000; z-index:1;
color:#ff0001; font-size:1px\">'+sy m+'<\/div>');
z = z + c1;
}
var z2=0,y2,x2 ;
for (i=0;i < ns1;++i) {
x2 = (px1 + r2*Math.cos(z2) ); y2= (py1 + r2*Math.sin(z2) );
document.write( '<div style=\"positio n:absolute; left:'+x2+'px;
top:'+y2+'px; height:4px; width:4px; background-color: #00ff00; z-
index:1; color:#00ff01; font-size:1px\">'+sy m+'<\/div>');
z2 = z2 + c1;
}
It turns out that the equations for the 2 circles are best solved in
terms of polar coordinates, and you loop over many points. You must
keep in mind that the origin of the display is taken at the upper left
corner of the monitor. The positive x direction points to the right as
usual, but the positive y direction points down in contrast to
pointing upward as usually used in math texts. This is just how
JavaScript math functions were set up - don't blame me for that :-).
Thus the key is a fair general knowledge of JavaScript or php, and a
good knowledge of their math functions as well as a knowledge of how
to solve mathematical equations in which you are interested. Every
equation is somewhat different. Thus it is easy to appreciate why
special programs are sold for solving math equations and plotting
results.For calculations that are very time consuming, fewer exact
points often are calculated and some type of extrapolation is used to
calculate points between the exact points.