1. can someone check this

I am trying to write a program that executes the improved Euler method of curve fitting. I am pretty sure i have written the code correctly to run it, but when it runs, the numbers get massive very quickly, and i worry i;m making a fundamental (C programming) error.

thanks

Code:
```int Euler(t, u, v, x0, y0, z0)

float t, u, v, x0, y0, z0;
{
float x[100], y[100], z[100], dxdt_i, dydt_i, dzdt_i,dx, dy, dz, dxdt_new, dydt_new, dzdt_new, dt = 1;
int i;

x[0] = x0;
y[0] = y0;
z[0] = z0;

system("cls");
printf ("\nLorenz formulas:\n\n");
printf("dx                          dy                             dz \n");
printf("--  = a(y - x)       :      --  = x(b - z) - y      :      --  = xy - cz\n");
printf("dt                          dt                             dt\n\n\n");

for (i = 0; i<5; i++)
{

dxdt_i = t*(y[i] - x[i]);
dydt_i = x[i]*(u - z[i]) - y[i];
dzdt_i = (x[i]*y[i]) - (v*z[i]);

dx = (t*(y[i] - x[i]))*dt;
dy = (x[i]*(u - z[i]) - y[i])*dt;
dz = ((x[i]*y[i]) - (v*z[i]))*dt;

dxdt_new = t*(y[i] - (x[i] + dx));
dydt_new = x[i]*(u - z[i]) - (y[i] + dy);
dzdt_new = (x[i]*y[i]) - (v*(z[i] + dz));

x[i+1] = x[i] +(dt/2)*(dxdt_i + dxdt_new);
y[i+1] = y[i] +(dt/2)*(dydt_i + dydt_new);
z[i+1] = z[i] +(dt/2)*(dzdt_i + dzdt_new);

printf("dx                          dy                             dz\n");
printf("--  = %.2f          :      --  = %.2f             :      --   = %.2f\n", dxdt_i, dydt_i, dzdt_i);
printf("dt                          dt                             dt\n");
printf("\nnew x = %.3f new y = %.3f new z = %.3f\n\n", x[i+1], y[i+1], z[i+1]);

i =  i++;
}
}```
P.S at the top where i sent the function the variables for x0, y0 and z0 and then on the next line i do this:

x[0] = x0;
y[0] = y0;
z[0] = z0;

its because i keep getting an error if i try and send the function a varaible to go straight into x[0]. I.e

int Euler(t, u, v, x[0], y[0], z[0])

can you not do this, it would neated things up abit...

also how do you control significant figures, on the off chance that it is working correctly, the numbers are too big and ruin my display.

If you cant control sigfigs, when i write this bit:

Code:
```printf("dx                          dy                             dz\n");
printf("--  = %.2f          :      --  = %.2f             :      --   = %.2f\n", dxdt_i, dydt_i, dzdt_i);
printf("dt                          dt                             dt\n");```
if the floating variables are big, then it messes up my nice rows. Can i control it so it is nicely tabulated?

2. Of course you can't pass in x[0], since the array x doesn't exist yet. Passing in a variable as you have it is the proper way to go.

If you haven't looked up printf yet, do so -- the f stands for formatted, after all, so you can specify your output format pretty exactly.

I didn't trace out the math very exactly, but I am not aware of a calculus-based formula for which setting a differential element (like dt) equal to 1 is even slightly appropriate. If 0.01 works, you're lucky, 0.001 or smaller is not uncommon.

3. If the x axis of a graph is time, the accuracy of my curve fit depends on how many points along the x axis i choose. For this i said that i would plot a point for every second that passes. Hence dt = 1.

Thank you for telling me about printf, when you begin programming, all you hear is printf lets you print to screen - i'll look it up now.

I just thought that if i could say

int lorenz (a, b)
float a, b;

i thought i might be able to say

int lorenz (a[0], b)
float a[10], b;

but if i have done it correctly thats fine, thank you.