Hi,
I've tried as you suggested, but results I get are not even near as I would like (values i got were (9.485, 11.471, 209.150)). Excel Solver did very good fit with values (3.146, 22.167, 250.976). Do you have any idea what's going wrong?
In the attachment I've added Excel file with values and with graph diagrams. Excel Solver is also configured, so all you need to do is to press SOLVE button. Agenda:
1. Black line - beginning function
2. Green line - reduced function (reduced function = beginning function/SRF)
3. Red line - estimated function (good solution is when green and red lines are lapped)
When you get values from ALGLIB fitter put them in I10 ,I11 ,I12 cells so u can compare graphs (it's respectively A,B,C).
This is whole code of my program:
Code:
using System;
using System.Collections.Generic;
using System.Text;
namespace FittingExample
{
class Program
{
public static void function_cx_1_func(double[] parameters, double[] x, ref double func, object obj)
{
double a = parameters[0];
double b = parameters[1];
double c = parameters[2];
func = x[0] * Math.Tan(a + (b / (1 + (x[0] / c)))*Math.PI/180);
}
static void Main(string[] args)
{
double[,] sigValues = {{0.000},{50.000},{100.000},{150.000},{200.000},{250.000},{300.000},
{350.000},{400.000},{450.000},{500.000},{550.000},{600.000},{650.000},
{700.000},{750.000},{800.000},{850.000},{900.000},{950.000},{1000.000}};
double[] tauValues = {0.000,34.011,59.616,80.539,98.557,114.634,129.346,143.057,156.013,168.384,180.291,191.825,
203.053,214.029,224.792,235.376,245.806,256.105,266.289,276.373,286.369};
double[] tauReduced = new double[tauValues.Length];
double sr = 3;
for (int i = 0; i < tauReduced.Length; i++)
{
tauReduced[i] = tauValues[i] / sr;
}
double[] initialGuess = { 10.2, 28.81, 250.988 };
double[] bndl = new double[] { 0.0001, 0.0001, 0.0001};
double[] bndu = new double[] { 10.2, 28.81, 250.988 };
double[] scale = new double[] { 1, 20, 200 };
double epsf = 0;
double epsx = 0.0001;
int maxits = 0;
int info;
alglib.lsfitstate state;
alglib.lsfitreport rep;
double diffstep = 0.0001;
try
{
alglib.lsfitcreatef(sigValues, tauReduced, initialGuess, diffstep, out state);
alglib.lsfitsetcond(state, epsf, epsx, maxits);
alglib.lsfitsetbc(state, bndl, bndu);
alglib.lsfitsetscale(state, scale);
alglib.lsfitsetscale(state, scale);
alglib.lsfitfit(state, function_cx_1_func, null, null);
alglib.lsfitresults(state, out info, out initialGuess, out rep);
Console.WriteLine("Without gradient: ");
Console.WriteLine("A= " + initialGuess[0]);
Console.WriteLine("B= " + initialGuess[1]);
Console.WriteLine("C= " + initialGuess[2]);
Console.WriteLine("RMS: "+ rep.rmserror);
Console.WriteLine("AVG Error: " + alglib.ap.format(initialGuess, 3));
System.Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}