Hi
Hope u can take ur time to help, i have to hand in a program within a few hours, ive written the code, but can't compile it
PROBLEM:
Problem: Consider a first order ODEs that describe the radioactive decay process:
u˙ + u = 0 and u(t = 0) = u0, (4)
Here, u(t) represent the flux of neutrons and is a radioactive decay constant. Solve this equation
using Euler’s method (3) to obtain a time profile of the function u(t). Following the Euler’s
solution, the difference equation for u at step n (time step tn):
un+1 = un
− unt. (5)
Your program should accept initial value u0 and as command line arguments. These should be
larger than zero (validate the input!). You should then setup a loop where you will advance your
solution in time using formula (5) (don’t forget to increment the time). The solution should be
written to the external file with the name given by idxxx prog4A.out where idxxx is your ITS
user id (ids start with ph for physics, cs for computer science, etc...). The file should contain two
columns separated by a single space: time t followed by u(t). You should consider following values
of parameters: u0 = 1.0, = 0.1 and t = 0.01 as a test. Then try other values (what happens
if >> t?). The number of points in your file should not be too large (no more than 10000
AND HERE IS MY CODE
Code:
#include <stdio.h>
#include <stdlib.h>
/* Function main() is defined so that
it can accept command line arguments */
int main(int argc, char* argv[])
{
double u_0, lambda, delta_t;
int i, n;
float u[5000];
float t[5000];
FILE *output;
output = fopen("xxx_prog4a.out", "w")
/* Check if two arguments were entered with
the program name. */
if(argc < 3)
{ printf("Two arguments needed!\n");
exit(EXIT_FAILURE);
}
else
{
/* Remember, all arguments are stored as
strings so we have to convert them to
numbers using sscanf */
sscanf(argv[1], "%lg", &u_o);
sscanf(argv[2], "%lg", &lambda);
u[0] = u_o;
t[0] = 0;
delta_t = 0.01;
N = 4500;
for (i = 0; i<N; i++)
{
t[i+1] = t[i] + delta_t;
u[i+1] = u[i] - (u[i] * lambda * delta_t);
fprintf(xxx_prog4a,"4.2%lf\t4.2%lf\n",t[i],u[i]);
}
fclose(output);
return(o);
}
}
and the errors are as following
"aab.c", line 20: syntax error before or at: if
"aab.c", line 24: syntax error before or at: else
"aab.c", line 41: warning: function prototype parameters must have types
"aab.c", line 41: warning: old-style declaration or incorrect type for: fclose
"aab.c", line 43: syntax error before or at: return
"aab.c", line 43: warning: old-style declaration or incorrect type for: o
"aab.c", line 45: syntax error before or at: }