Fit data in the textArea, show result in log and create plot. @param fitType as defined in CurveFitter constants @return false on error.
(int fitType)
| 82 | * @return false on error. |
| 83 | */ |
| 84 | public boolean doFit(int fitType) { |
| 85 | if (!getData()) { |
| 86 | IJ.beep(); |
| 87 | return false; |
| 88 | } |
| 89 | cf = new CurveFitter(x, y); |
| 90 | cf.setStatusAndEsc("Optimization: Iteration ", true); |
| 91 | try { |
| 92 | if (fitType==USER_DEFINED) { |
| 93 | String eqn = getEquation(); |
| 94 | if (eqn==null) return false; |
| 95 | int params = cf.doCustomFit(eqn, null, settings.getState()); |
| 96 | if (params==0) { |
| 97 | IJ.beep(); |
| 98 | IJ.log("Bad formula; should be:\n y = function(x, a, ...)"); |
| 99 | return false; |
| 100 | } |
| 101 | } else |
| 102 | cf.doFit(fitType, settings.getState()); |
| 103 | if (cf.getStatus() == Minimizer.INITIALIZATION_FAILURE) { |
| 104 | IJ.beep(); |
| 105 | IJ.showStatus(cf.getStatusString()); |
| 106 | IJ.log("Curve Fitting Error:\n"+cf.getStatusString()); |
| 107 | return false; |
| 108 | } |
| 109 | if (Double.isNaN(cf.getSumResidualsSqr())) { |
| 110 | IJ.beep(); |
| 111 | IJ.showStatus("Error: fit yields Not-a-Number"); |
| 112 | return false; |
| 113 | } |
| 114 | |
| 115 | } catch (Exception e) { |
| 116 | IJ.handleException(e); |
| 117 | return false; |
| 118 | } |
| 119 | IJ.log(cf.getResultString()); |
| 120 | plot(cf); |
| 121 | this.fitType = fitType; |
| 122 | return true; |
| 123 | } |
| 124 | |
| 125 | String getEquation() { |
| 126 | GenericDialog gd = new GenericDialog("Formula"); |
no test coverage detected