438,746 Members | 1,928 Online Need help? Post your question and get tips & solutions from a community of 438,746 IT Pros & Developers. It's quick & easy.

# Ploting or drawing a mathcurve

 P: n/a 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? Please help me Aug 26 '08 #1
7 Replies

 P: n/a serave wrote: 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? You may be able to do this using either IMagick or GD. These are your php options. You may find this easier to do client side with either flash or javascript. Jeff Please help me Aug 26 '08 #2

 P: n/a On Aug 25, 9:18*pm, serave

 P: n/a On 26 Aug, 07:53, cwdjrxyz But you might want to look at Google charts or JPgraph for simple solutions for rendering chart plots (but you'll need to generate numerical data yourself). C. Aug 26 '08 #4

 P: n/a On 26 ago, 01:53, cwdjrxyz

 P: n/a Message-ID: No i just need to draw the function, no need to draw the bestaproximation. Is just drawing the curve based on a mathematicalequation like y=e^(x-5)+sin(5x^3)-45x^(2/3) or something like that Presumably you'd have to specify a range? If so a simple for loop would be all you'd need to generate the input array for something like jpgraph. -- Geoff Berrow 0110001001101100010000000110 001101101011011001000110111101100111001011 100110001101101111001011100111010101101011 http://slipperyhill.co.uk - http://4theweb.co.uk Aug 26 '08 #6

 P: n/a On Aug 26, 10:55*am, serave '+sym+'<\/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('
'+sym+'<\/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. Aug 26 '08 #7

 P: n/a On Aug 26, 12:46*pm, cwdjrxyz 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,r3=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('
'+sym+'<\/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('
'+sym+'<\/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. Ther is a free program for plotting data available from the US NIST (know as the Bureau of Standards in the past). It will not do as much as the newer commercial programs, but you can't argue with the price. The name of the prograsm is dataplot. It is available in several versions including C and a PC version which is likely the one you would want. Download sometimes is slow in the daytime in the US, so you may want to try in the evening. Go to ftp://ftp.nist.gov/pub/dataplot/ . then select "pc". On the pc screen select ReadMe.Doc and it will tell you where to go from there. There are a few files to download and it will take some time to learn how to do everything it can do. I have not used DataPlot in recent years, but it worked fairly well in the past. Aug 26 '08 #8

### This discussion thread is closed

Replies have been disabled for this discussion. 