Hey,
First thing to note is I am new, if I am in the wrong thread or I am clashing with any other forum regulations I would ask to be kindly redirected.
My query is probably simple, I have recently begun programming c within my university course. I have been given a task to add arrays to a program I had previously made to make it record the values as I expect I will then quote them on an exported document.
Code:
#include <stdio.h>
#include <math.h>
main()
{
int i; // step counter
float theta[10000]; // initial value for angle
float omega; // initial value for angular speed
float time[10000]; // array of possible time values
float dt = 0.01; // time step
int steps = 100; // number of steps
float l = 4.04; //length of string
float g = 9.81; //gravity
time[0] = 0; //time starts at 0
//values theta cant go past
printf("What would you like the initial speed to be?\n");
scanf("%f",&omega);
printf("What angle will you drop it from?\n");
scanf("%f",theta[0]);
for(i=0; theta[i]=0; i++){
time[i] = time[i-1]+dt;
omega = omega-(g/l)*dt*sin(theta[i]);
theta[i] = theta[i-1]+omega*dt;
printf("Step number %i, Time equals %f, Theta = %f omega = %f\n",i,time[i],theta[i],omega);
}
if(theta[i] == 180 || theta[i]== -180){
printf("\a");
}
}
This is what I have written so far, you can probably see what I am expecting. The pendulum is meant to swing and take gravity into account, then it is meant to loop and record values for the step count, time, theta and omega (mainly theta and omega required). The boundaries are set so once the angle of theta reaches 180 degrees it then stops. I believe the problem lies in the way I have created my theta array, however, I don't properly know how to implement this. Upon launch it asks for omega, as required, after inputting the value it crashes.
It is probably an extremely simple matter but I have tried this in the space of two days of learning code so please bear with me, a brief explanation would be greatly appreciated so I understand why the changes have been made!
Thank you!