Question: Regarding physics computations: To make the experience smoother we will use a testing framwork called check Newton II solver, was created, to compute a projectile's
Regarding physics computations:
To make the experience smoother we will use a testing framwork called check
Newton II solver, was created, to compute a projectile's trajectory under gravity and air resistance drag using initial position and velocity. Each time step updates position and velocity based on acceleration from gravity and drag:
where alpha is proportional to drag and beta to particle mass.
Our solver is currently broken. Your task: find and fix the bug so all tests pass. Use unit tests as guidance. See the section "The makefile and project structure" for running instructions. If the program hangs, press CTRLC to stop.
Main file:
#include printf
#include malloc
#include "vector.h
void
printvector
double vec Vector to print
unsigned int ndims Number of dimensions
for int i ; i ndims; i
printff veci;
void
solvegeneral
double pos Position vector. Initialize with initial position
double vel Velocity vector. Initialize with initial velocity
double gravity Vector with the opposite direction of gravity
unsigned int ndims Number of dimensions of vectors
Constants
const double dt f; Simulation time step
const double alpha f; Proportional to drag coefficient
const double beta f; Proportional to mass
double tmp double mallocsizeofdoublendims; Buffer for storing intermediate work
double time f; Simulation time
Print header
printf# Column : Time
;
printf# Columns ii: Position
ndims;
printf# Columns ii: Velocity
ndims ndims ;
Print positions and velocity
printvector&time, ;
printvectorpos ndims;
printvectorvel ndims;
printf
;
while
Update position by adding velocity times dt
constantmultiplicationtmp vel, dt ndims; tmp vdt
elementwiseadditionpos pos, tmp ndims; pos pos vdt
Compute acceleration from drag, multiply with dt and add to velocity
constantmultiplicationtmp vel, alpha, ndims;
constantmultiplicationtmp tmp dt ndims;
elementwiseadditionvel vel, tmp ndims;
Compute acceleration from gravity, multiply with dt and add to velocity
constantmultiplicationtmp gravity, beta, ndims;
constantmultiplicationtmp tmp dt ndims;
elementwiseadditionvel vel, tmp ndims;
Update time
time dt;
Print positions and velocity
printvector&time, ;
printvectorpos ndims;
printvectorvel ndims;
printf
;
Break the simulation when below in the dimension of gravity
if dotproductpos gravity, ndims
break;
freetmp;
tmp NULL;
void
solved
double posfff; Position
double velfff; Velocity
double gravityfff; Gravity is directed in negative y
solvegeneralpos vel, gravity, ;
int
main
solved;
return ;
vector file
#include
#include "vector.h
void
elementwiseaddition
double res
double v
double v
unsigned int len
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
