Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I extracted values from datagridview1 to calculate an exponential equation.

foreach (DataRow pr in Global_var.data_source.Tables[0].Rows)
{
    try
    {
        x1 = (double)pr[0];
        y1 = (double)pr[1];
        chart1.Series[1].Points.AddXY(x1, y1);
        chart1.Series[1].ChartType = SeriesChartType.Spline;
    }
    catch
    {
        x1 = 0;
        y1 = 0;
        MessageBox.Show("");
    }
} 

int number_of_rows = Global_var.data_source.Tables[0].Rows.Count;

foreach (DataRow pr in Global_var.data_source.Tables[0].Rows)
{
    xpriemer += (double)pr[0];
    lny *= (double)pr[1];
    sxy += (double)pr[0] *Math.Log((double)pr[1]);
    sxx += (double)pr[0] * (double)pr[0];
    syy += Math.Log((double)pr[1]) * Math.Log((double)pr[1]);
}        

xpriemer /= (double)number_of_rows;
xpriemer = Math.Round(xpriemer, 4);
/////////////
lny = Math.Round(lny, 4);
lnyc = Math.Log(lny) / (double)number_of_rows;
lnyc = Math.Round(lnyc, 4);
//////////
sxyc = sxy - (number_of_rows * xpriemer * lnyc);
sxyc = Math.Round(sxyc, 4);
///////////
sxxc = sxx - (number_of_rows * xpriemer * xpriemer);
sxxc = Math.Round(sxxc, 4);
///////////
B = sxyc / sxxc;
B = Math.Round(B, 4);
//////////
A = Math.Exp(lnyc - B * xpriemer);
A = Math.Round(A, 4);
////////////////
syyc = syy - number_of_rows * lnyc * lnyc;
///////
r = (sxyc / (Math.Sqrt(sxxc) * Math.Sqrt(syyc)));
r2 = sxyc * sxyc / (sxxc * syyc);

After I need to calculate Y1exponential for every row in column X1 like shown here:
y1expo = A * Math.Pow(e, B*xforeveryrow);
e = 2.71828182;


And then put the values for y1exponential to chart1. Do i need to create a second datagridview?, to put the x1,y1expo values there to create and exponential spline?

For examples i provided picture, as well a picture of my program: Picture of example and the program[Imgur]

What I have tried:

I solved everything until now, i dont know how to continue.

I tried doing something like:
pr[1] = A * Math.Pow(e, B*pr[0])


but that didnt work.
Posted
Updated 8-Apr-22 5:39am
v6
Comments
[no name] 9-Mar-22 11:57am    
You need a "function" (of x and y) if you plan to generate meaningful values.

Examples of graphing exponential functions: https://www.brainfuse.com/jsp/alc/resource.jsp?s=gre&c=35250&cc=108825

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900