Want to do curve fitting !!

Hi,
I'm new to Java but want to do curve fitting codes using Java 2D or Java 3D but don't have the time to read a whole bunch of tutorials / books.
I've managed tto create a basic class within my objects, then I get rather tired. wonder any one got some hints for me to finish the job.
I hope to create an applet that accept coordinates in a large text box,
as ::
x1, y1 <--|
x2, y2 <--|
x3, y3 <--|
x4, y4 <--|
x5, y5 <--|
x6, y6 <--|
then the applet draws a fitting curve that goes through all the points
given as input.

Am i right, that you write the code for calculating the code, and you now want to know how to get in on the screen?
if so, the easiest way would be, not to use Java3D at all.
Just build up a Windows (e.g. JFrame), attach a JPanel for example and use the paint(Graphics g) method, that comes with every class derived from Component or JComponent.
With the given Graphics-Object you can put lines, single pixels and more onto the component.
Just have a look at here, what posibilies you have:
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Graphics.html
I hope i could help you.
Sash

Similar Messages

  • How to use the parameter "data" in the vi of Nonlinear Curve Fit

    I used "Nonlinear Curve Fit" to do state estimation. If I make the number of unknows a constant number, it is fine to code the fitting model for f(x,a). But if I want to code the number of unknows as a variable, how can I do this?
    Maybe "data" should be used here. But I just could not find any examples talking about how to use "data" here.
    Thanks.

    Hey hilary,
        Have you looked at the LabVIEW help for the Nonlinear Curve Fit VI?  Which version of LabVIEW are you using?  In mine, the VI is polymorphic, and you can declare the formula to be a formula string.  Then it provides pins to enter the input parameters programmatically.  Perhaps you could post a screenshot of how you are currently using the VI, and we could help more.
    Brian B
    Field Sales Engineer
    Tennessee/Southern Kentucky
    National Instruments

  • Constrained Nonlinear Curve Fit VI: Termination Revisited (LabVIEW 8.5)

    Hello:
    In the Constrained Nonlinear Curve Fit VI, the Help for the VI states that if the number of iterations exceeds max iterations specified in the termination control, the fitting
    process terminates. Would this not indicate that if the above condition is met, the number of iterations recorded (an output of this VI) should be equal to the max iterations specified (since the VI is exits at this point).  I believe I have seen situations where this condition is met, yet the number of iterations recorded is greater than the max iterations I have specified in the termination control.  Has anyone else seen this?
    Thanks,
    Don

    Don,
    Just wanted to clarify the termination criteria for the nonlinear curve fitting routines.  There are two criteria used to terminate the fitting process:
    "max iteration" and "tolerance".  The main while loop terminates when either of these conditions is met, so:
    IF( (current_iteration > max_iteration) OR (current_tolerance <= tolerance) ) THEN (terminate loop)
    "current iteration" is just the current loop counter(starts at 1 for the first iteration).  This term is mainly a guard against having the fitting process run too long.
    tolerance is computed as the relative change between the current and previous weighted least squares values.
    Let wls = SUM_OVER_ALL_X( weight(x)*(f(x,a)-data(x))^2 )
    current_tolerance = ABS(current_wls - previous_wls)/(ABS(current_wls) + machine_epsilon)
    where ABS indicates absolute value.  Adding machine_epsilon to the denominator is just a guard against division by zero.
    For the bound nonlinear curve fit VIs, if the "method" input is chosen to be LAR or bi-square, then wls is defined as:
    wls = SUM_OVER_ALL_X( weight(x)*reweight(x)*(f(x,a)-data(x))^2 )
    where reweight(x) is a term reducing the weight of high-leverage data points.
    For both the constrained and unconstrained fitting routines, if the weight input is unwired then all points are considered to have a weight of 1.
    Christian has nicely covered the difference between the number of iterations and the number of function calls.  If your
    When the fitting process terminates the best result obtained so far is returned.  As you noted, this may be a good result, although the algorithm may not have completely converged yet.
    -Jim

  • Nonlinear curve fit

    Hi everybody,
    I am trying to fit a custom nonlinear curve to my data. I want to fit a curve to the data twice. After the first fit, I want to use the coefficient a (6.57962) in my second curve fit as my coefficient b. When I try to use this and create a custom equation by string concetanete, everything seems fine but I do not get what I expect to get. To double check I used curve fitting express VI and I added 6.57962 as a coefficient in my equation and at the end a turns to be 6.752. However, this does not happen in my second curve fit. Does anybody have any idea what might be wrong? I cannot find my mistake, could you please help me?
    Thank you very much
    Attachments:
    Read.vi ‏129 KB
    read.png ‏66 KB

    The errors you get provide some clues, although they are not very explicit.
    The -23001:  Syntax error of parser  is usually a sign that your string describing the function is ill-formed or that there is a parameter mismatch. You have both.
    The string array constant feeding into the second Lev-Mar VI has two elements, the second one being an empty string.  Even though the string is empty, the parser expects two elements in the Initial Parameters array. But since your equation has only one parameter (a), the proper solution is to remove the blank element from the constant array.
    The other problem is that the first Initial Parameters array is empty.  Maybe you always enter two values but I did not know what to put in. 
    The second fit is somewhat sensitive to the initial Parameter value. Negative values do not work. 1 returns 6.753... 2 through 6 and 8 (integer values only) return 6.246... 7 returns the same result as 1. Values 10 and above return the value entere with error -20041 (singular matrix) appearing at >=12.
    The initial b parameter in the first fit does not matter over a fairly wide range.
    I also noticed that you seem to have a severe allergy to straight wires. Wires running all over the diagram and particularly behind other objects makes it very hard to read your code. Dataflow along the wires should generally be from left to right as much as possible. The code works the same regardless of the number of bends in the wires but straighter wires are much easier on the programmer.
    Lynn

  • Nonlinear Curve Fit and using static data

    I am trying to fit data to a 2D function using the Nonlinear Curve Fit VI in Labview 8.2.1, but I would like to also include 2 parameters that I don't want to be optimized.  I cannot directly use constants since every time I run the fitting I need to change the 2 parameter values.  I tried to modify the example by Altenbach according to my own application in the link below. 
    http://forums.ni.com/ni/board/message?board.id=170&message.id=230831
    I think the problem is that I don't completely understand how to use the static VI reference with the Nonlinear Curve Fit VI?  It looks like there is a static data control that I could use to add additional parameters, but I am not sure?  I can get Altenbach's code to work if I change the function to something different, and even if I change the number of inital fitted parameters.  I just can't figure out how I can add parameters using a control that will not be optimized.  I can attach an example, but it is very similar to Altenbach's code except the function is different, and I am trying to add additional parameters that are not optimized.  Thanks for any help.
    Kevin Baker 

    Thanks Trey.  I am sorry I didn't make it clear what I was talking about before.  I am attaching an example that will hopefully clarify what I would like to do.  When I try to pass the static reference to the Nonlinear Fit VI it says gives me a broken wire and says "function conflict".  I am assuming the problem is that I inserted another control to the VI when I wasn't supposed to.  I just don't know of any other way to pass data into the VI, and still have the Nonlinear Fit VI still work?  What is the "data" control in the Nonlinear Fit VI used for anyway?  It seems that that it was want I need, but I don't know how to use it?  Thanks again for any help.
    Attachments:
    Fit equation.vi ‏15 KB
    general lorentzian.vi ‏26 KB

  • Why doesn't my non-linear curve fit finish?

    I am working with an experiment that gives me X- and Y- data that I need to fit to a theoretical model (somewhat involved). I use to do this in matlab using the "lsqcurvefit", which works fine,
    but for varous reasons I need to do this in LabView instead.
    So, first thing I did was to make a vi which is my theoretical model. I throw in my X-data and get the Y data out of it.
    This vi works fine of it's own, but now I want to do my fitting by calling the model-vi from the Nonlinear curve fit.vi. I enter the same initial parameters, termination conditions, upper- and lower boundaries as in the matlab code, but no matter what, after some 100 function calls, the curve fit interrupts and tells me:
    "Error -20041 occurred at NI_Gmath.lvlib:Nonlinear Curve Fit LM.vi
    Possible reason(s):
    Analysis:  The system of equations cannot be solved because the input matrix is singular."
    I have tried to locate the problem at varoious levels but I get confused when I start to look into the nonlinear curve fit vi, I just lose myself in tons of block-diagrams.. Can anyone see what my problem is? I'd sure appreciate it! I added the necessary files. Main vi: langevin fit. vi, then open the data.txt.
    Thanks
    Attachments:
    langevin fit.zip ‏94 KB

    Your model function does not produce anything resembling your data. As a first step, graph the data using your initial guesses, here's how it would look.
    Here' the data and your initial guess on the same graph. You need to find initial guesses so the output resembles your data.
    My best guess is that your model is faulty. It is very hard to debug, because it is a mess: deeply stacked sequence structures and unneeded local variables. Also the model parameter constants should be provided via the "data variant" input instead of a global variable. You have a weird mix of datatypes. Why is half of the stuff EXT instead of DBL for no reason?
    I would also highly advise NOT to color your own VIs light yellow. Don't make them look like system tools!
    I am busy today, but maybe I can have a stab at it tonight. Good luck!
    Message Edited by altenbach on 07-06-2009 08:59 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    langevinFit.png ‏21 KB

  • Curve fitting only part of a waveform

    I am taking some data from an Oscilloscope and I need to do a curve fit.  As you can see from the data in the attachment the data begins at 0 and ends a 10e-6.  I just want to curve fit the part from 5e-6 to 10e-6.   This is what I have tried
    1) I take the waveform and use a "Get Waveform Components".  I then take the Y data and strip off the first half of the data from the array.  Then I  use a "Build Waveform" and put in the new Y data and the dt data to make the NEW waveform.  I then put it in to the Curve Fitting Express VI.  This works well for the slope, but of course the intercept is off because the data that was at 5e-6 is now at 0.  And the data at 10e-6 is now at 5e-6 since I stripped off the first 5e-6 of data and rebuilt the waveform.   I thought I could use the "t0" value in the "Build Waveform" to set the start of the NEW waveform to be 5e-6, but it seems that the "t0" is only for a timestamp (its a calendar data). 
    2) I thought about converting the waveform in to X and Y data because it would be easy to shift the X data by just adding 5e-6 to each value in the X array.  But then it wouldn't input to the Curve Fitting Express VI. 
    3) I thought about using the "Locations" input to the Curve Fitting Express VI, but I haven't really been able to get that to work. 
    Thanks for any help. 
    Solved!
    Go to Solution.
    Attachments:
    graph.jpg ‏128 KB

    Hello,
    Check out these examples and online docs relating to curve fitting. Perhaps they will be of some use.
     5th-order Curve Fitting Using Curve Fitting Express VI
    Linear Curve Fitting a Random Waveform Graph
    Overview of Curve Fitting Models and Methods in LabVIEW
    Introduction to Curve Fitting
    Best,
    National Instruments
    Applications Engineer

  • 2 real-time plots + curve fits on the same x-y graph

    Hello all-
    Per the title, I'm trying to plot two series, both in real time, plus curve fits for each series on the same x-y plot.  Some background on the subject - this will be used to show the temperature distribution across a counter-flow heat exchanger.  So the x-y plot will plot temperature vs. position for two different flow streams - a hot flow stream, and a cold flow stream.  I would like to plot them both on the same graph so the temperature relationship between the two flows can be clearly seen.  If I can plot 2 series with simple lines connecting the points that would be fine, but would prefer some smoothing on the line or using a curve fit if that is possible to do in real time.
    A screen shot of my block diagram is linked below.  As you can see, the diagram is symmetrical with the inputs from the cold flow being processed on the top, and the inputs from the thermocouples in the hot flow being processed at the bottom.  I've got 2 issues:
    1.  Plotting 2 series on the same X-Y graph in real time.  (I've done this before, but never in real time).  Am I correct in assuming, if I append the array so it is a 3-D array (X, Y1, Y2), that I can plot both series on the same X-Y graph?  The individual X-Y graphs are functional, but I would like to combine them.
    2.  I've circled a bundle output which outputs the X,Y values of a curve fit.  The output here is a string (pink wire), so I cannot plot it on the X-Y graphs which are shown, due to it being 2 different data types.  Is there any way to plot the curve fit on the same graph?  Is LabVIEW capable of doing this in real time?
    Thank you for any help...   I realize that some of the answers here may be obvious, but visualizing what's going on in LabVIEW is a bit of a challenge for me, since I'm used to seing text-based code in VBA and MATLAB.
    Attachments:
    HX Block Diagram 2.jpg ‏302 KB

    The output you have circled is a cluster of two 1D arrays, not a string.
    XY graphs take a varirty of inputs (array of points, cluster of x and y arrays, complex arrays, etc.) but you cannot mix datatypes in a single graph. Since you are graphing arrays of points (a point is a cluster of an x and y scalar), you need to do the same for the data you circled. Simplest would probably be to just wrap an autoindexing for loop around the bundle function. See how far you get.
    If you want detailed help, please attach your actual VI. We cannot debug a picture.
    LabVIEW Champion . Do more with less code and in less time .

  • Quadratic & cubic curve fitting ???

    I hope this is just a simple one :
    I need to do a curve fitting applet, what's the difference
    between quadratic & cubic curve fitting methods ???
    & how do I write such methods ???

    genetic algorithms... but that is far fromsimple...
    A bit over the top for what he wants!
    nah... 5 min job ;0)

  • Curve fitting problem

    hi everybody,
    i want to investigate thermocouple behaviour to a temperature  transient change.am using USB 6008 and gate & trigger VI with curve fiiting VI. Whenever I run the program, I get the following error message- Analysis:  The system of equations cannot be solved because the input matrix is singular  with the Curve fitting VI being highlighted.
    Anybody with clue on what am not doing right would be highly appreciated.
    Pls find the attached file.
    Thanks.
    KDGREAT
    Attachments:
    curve fitting.vi ‏132 KB

    KDGREAT. wrote:
    My initial conditions: a=13,b=1,c=25.
    The data is a thermocouple signal (response to a sudden temperature change). I also need to be able to capture the signal using GATE and TRIGGER VI.
    I don't really care where the data comes from, but why can't you attach some typical data so we can try to reproduce the error??
    If you graph some simulated data using your initial conditions, does it look anything like your data?
    In the VI you attached, the initial conditions are 1,1,1 and not 13,1,25
    LabVIEW Champion . Do more with less code and in less time .

  • Curve fit

    Hi! I want to ask how I can fit a curve and see this in the graph for the obtained 2d array.
    I can obtain a 2d array (x-y) as a result of loop iteration clicking "Next Step" button for 14 times. After that, I want to fit a curve for this 2d array as a function of y=f(x).
    Also, I want to see the formula, and also function coefficients for this curve.
    I have tried a curve fitting as can be seen from the attached picture. However, it always failed. I can not obtain purely x-y curve (y=f(x)). Also, I have attached the sample VI. Could anyone help me ? I'm looking forward to hearing from you.
    Solved!
    Go to Solution.
    Attachments:
    sample_the_latest_one.vi ‏182 KB
    blockdiagram.JPG ‏51 KB

    Could you attach a typical data file? Thanks!
    Even better, create an indicator on the 2D array leading to the second loop. Run the VI and start fitting so the indicator contains 2D data. Now make the new indicator a constant with typical data (right-click terminal...change to constant). Now save and attach the VI. 
    mechen wrote:
    I attached the second while loop to use its stop button. I defined its stop button as a "Curve Fitting" button as can be seen from the front panel.
    Why not make it a state machine with a single loop? Your data is already in shift registers, so it would be available in the main loop. All you need is another state. The way you program it, you cannot easily go back to reading new data without additional code. Your fitting loop still needs a small wait or an event structure. Fitting needs to be done only of one of the inputs changes and not millions of times per second. You also don't need to wire all inputs, only the ones you want different from the defaults.
    Why do you have two instances of the same 2D array diagram constant. This makes the code unmaintainable, because identical changes would need to be done in two different places if you need to modify things in the future.
    mechen wrote:
    My question is how I can obtain a graph for 2d array.
    The x-axis will be the first column of the 2d array. The y-axis will be the second column of the 2d array.
    If x is not spaced equally, you need an xy graph. Simply extract the two columns using "index array", then bundle them into an xy graph. Check the shipping examples.
    LabVIEW Champion . Do more with less code and in less time .

  • How can I apply curve fitting to simple BER measurement data?

    I am collecting simple BER data from a communications receiver for modulations such as PSK, CPM, etc. The data looks good but has the usual measurement noise, which I would like to spiffy-up for customer presentations.
    I have tried virtually all of the vi's in the LV Fitting palette, with little or no success. One of the NI AE's provided me with a GP Fit approach, but it has problems when you introduce error. I have attached a vi which demonstrates this, and also shows an attempt on my part to use the Least squares vi, with various functional estimates of the erfc vi. The vi also includes sample data.
    I see MatLab (and possibly Wolfram) has a function specifically for BER smoothing, but NI doesn't, as best I can tell. I feel certain that one or more of the LV fitting vi's can be coerced into working with the correct parameters - but so far I can't find them!
    Has anyone tackled this problem with good results?
    One other thing - has anyone else noticed that the formula used by the LV erfc (complementary error function) is *not* the standard model used for BER/radio communications applications?
    Appendix B of Digital Communications by B. Sklar gives the conversion:
    Q(x) = 1/2 erfc (x/sqrt(2)), where erfc (x) is the LabView vi block.
    Thanks,
    Mark

    Hi Eric,
    Well, BER is just data measured at certain input levels to a receiver. For digital communications systems, we typically use Eb/No to specify the input signal strength, and measure the BER at that level. This is analagous to signal-to-noise ratio (SNR) measurements in the analog domain.
    The BER values tend to run from between .01 and 10E-5, or even 10E-9 for high performance systems. As a result of the wide range of BER values, it is usually plotted on a logarithmic (y-axis) scale. Values of Eb/No are in the range of a few dB, up to perhaps 15~20 dB. So the x-axis is normally 'linear', although in dB.
    I have attached the vi's again, and if you run the LS BER fit vi, you will see the data plotted. If you turn off the noise, you can see a very nice plot - the curve fit vi works fine. But if you add noise (which simulates what you would measure in a real system), and run it several times, you will see all kinds of responses - depending on the noise parameters. What I am looking for is something that gives me a nice smooth graph even with the noise turned on (which is what my real data looks like).
    Thank you,
    Mark

  • Nonlinear Curve Fit LM Formula String in Labview 8

    hi, guys. I write a vi which use Nonlinear Curve Fit LM Formula String. When I run it ,the program says "Syntax error of parser." and I don't know what's wrong with it, so help me,Please. By the way ,you can fill the arrays as you wish.
    帖子被trinight在02-11-2006 07:51 PM时编辑过了
    Attachments:
    curve fitting.vi ‏16 KB

    You MUST wire initial estimates for the parameters. Attached modification works just fine.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    curveFittingMOD.vi ‏17 KB

  • How to create curve fitted line chart?

    Line chart is formed with straight lines, but how to create curve fitted line chart?

    Jasper wrote a blog on curve fitting charts

  • Curve Fitting

    Hi 
    I have a set of measurement data that i wish to fit to a complex curve.
    After the fitting i need to find the constants from the curve and use them for further calculations.
    equation for my curve is 
    x= -a* integral(p^n dt) + c.,
    where x,p are known data sets at time t. 'a' and 'n' and 'c' are constants. after the fitting i have to find best values for a and n.
    somebody please explain how i can accomplish this.
    Waiting For the inner calling

    Inorder to use the  Levenberg-Marquart method, it is neccessary to specify the formulae string. but how can i specify a formula containing integral function as a labview string.
    Warm regards
    Deepu Jacob
    DFGray wrote:
    You have two main options:
    Convert the integral to an actual equation, then use a non-linear fitting routine, such as the Levenberg-Marquart, to do your fit. You will need approximate values for your parameters before you start.
    Use one of LabVIEW's numeric integrators to do your integral, and use a non-linear fitting routine to find the parameters. This will be slower.
    Before you go any further, I would strongly recommend you read the chapters in Numerical Recipes, 10 and 15, about fitting data to parameters. Nonlinear curve fitting can be very finicky, so you need to know what you are doing. LabVIEW has all the algorithms (if you have a student, full, or pro version), so you won't have to code much more than your actual function.
    Good luck! Let us know if you run into problems.
    Waiting For the inner calling

Maybe you are looking for

  • File context menu disappears (in shared folder, if some files in it are bein modified)

    Hi! The problem is: When I'm in Windows Explorer in shared folder on network drive (SMB), trying to open context menu for any file in this folder, it will show and then disappear in ~1 second, so I can't have time to select item in context menu, espe

  • Home Office Network Software Challenges - Post HP Support Assistant Update

    Hi I have an existing home office network setup on an HP Officejet 7410 with assistance from 'Dean' at the end of 2009 / early 2010. Essentially I have a relatively new HP Compaq 6000 Pro MT Windows 7 32 bit main desktop connected by ethernet  to a N

  • Drop shadow across spread

    I have applied a drop shadow to an image which has been placed across a spread. The drop shadow displays as expected on the screen and when exported as a PDF, however when the spread prints from InDesign extra shadow is added down the middle of the s

  • Importing web pages as graphics

    I'm trying to import a webpage into a sequence montage. I can't seem to figure out a way to turn the page into a "snapshot" to then import as a .jpg or .tiff into FCP. Any suggestions?

  • Ipod touch home botton stopped working

    hey everytime i push and hold the home button on my 2nd gen ipod touch to move the icons, it does not work..i've tried everything. any ideas would be great because i just updated to the iphone software OS system 3.0 and now my home button does not wo