what s the quetion

Get perfect grades by consistently using Writerbay.net writing services. Place your order and get a quality paper today. Take advantage of our current 20% discount by using the coupon code GET20


Order a Similar Paper Order a Different Paper

please use matlab to get all the graphs, an write the answer with logic clearly.

please notice each question and answer everyone.

and get all the graphs.

here is the sample code

/* This is a very primitive, standard c code [NOT FOR DISTRIBUTION] that will show the_x000D_
   basics of a second order finite difference approximation to the wave eqaution without_x000D_
   damping -- as described in the problem set._x000D_
   compile with_x000D_
   cc -O3 -o run.job main_sample_MAT128C_4.c -lm_x000D_
   or_x000D_
   gcc -O3 -o run.job main_sample_MAT128C_4.c -lm_x000D_
   then run the job with_x000D_
   run.job_x000D_
   or _x000D_
   ./run.job_x000D_
*/_x000D_
_x000D_
#include <stdio.h>_x000D_
#include <string.h>_x000D_
#include <math.h>_x000D_
#include <stdlib.h>_x000D_
#include <sys/types.h>_x000D_
#include <sys/times.h>_x000D_
#include<sys/param.h>_x000D_
_x000D_
#define BUF1 32_x000D_
_x000D_
int main()_x000D_
{_x000D_
   /* Declare variables */_x000D_
   int     n_dt, n, j, mm;_x000D_
   double  *f_now, t0, tn, y0, *y_now, *y_new, *y_pre, eta;_x000D_
   double  v0, vn, vm, a, b, c1, c2, c3, c4, norm1, norm2;_x000D_
   double  t_start, dt, x_l, x_r, y_l, y_r, dx;_x000D_
   /* This is for opening a file -- leave it as is unless you know what you are doing */_x000D_
   char    *rundat = "Dat";_x000D_
   char    datfile[BUF1];_x000D_
   FILE    *f_dat;_x000D_
_x000D_
   /* Declaration of right-hand side of differential equation */_x000D_
   extern double func();_x000D_
_x000D_
   /* Open the data file Dat  -- leave it as is unless you know what you are doing */_x000D_
   sprintf(datfile, "%s", rundat);_x000D_
   if ((f_dat = fopen(datfile, "w")) == NULL) {_x000D_
      fprintf(stdout, "Can't open Dat filen");_x000D_
      fflush(stdout);_x000D_
      exit(1);_x000D_
   }_x000D_
_x000D_
   /* Set system parameters */_x000D_
   eta   = 0.5;_x000D_
_x000D_
   mm = 1000; /* Number of spatial segments */_x000D_
   x_l = 0.0;  /* Boundary Conditions */_x000D_
   x_r = 10.0;_x000D_
   dx = (x_r-x_l)/mm; /* spatial segmentation */_x000D_
   y_l = asin(eta);_x000D_
   y_r = y_l+2.0*M_PI;_x000D_
_x000D_
   t_start = 0.0;                /* initial time */_x000D_
   dt  =   0.009;              /* time step */_x000D_
   n_dt    = 100000;            /* maximum number of time steps */_x000D_
_x000D_
   /* Create arrays */_x000D_
   if ((y_pre = malloc((mm+1)*sizeof(double))) == NULL) {_x000D_
      fprintf(stdout, "problems with allocating memory for y_pren");_x000D_
      fflush(stdout);_x000D_
      exit(1);_x000D_
   }_x000D_
   if ((y_now = malloc((mm+1)*sizeof(double))) == NULL) {_x000D_
      fprintf(stdout, "problems with allocating memory for y_nown");_x000D_
      fflush(stdout);_x000D_
      exit(1);_x000D_
   }_x000D_
   if ((y_new = malloc((mm+1)*sizeof(double))) == NULL) {_x000D_
      fprintf(stdout, "problems with allocating memory for y_newn");_x000D_
      fflush(stdout);_x000D_
      exit(1);_x000D_
   }_x000D_
   if ((f_now = malloc((mm+1)*sizeof(double))) == NULL) {_x000D_
      fprintf(stdout, "problems with allocating memory for f_nown");_x000D_
      fflush(stdout);_x000D_
      exit(1);_x000D_
   }_x000D_
   /* Initial condition */_x000D_
   t0 = t_start; /* initial time */_x000D_
   tn = t0;_x000D_
_x000D_
   for (j=0; j<=mm; j++) {_x000D_
      y_pre[j] = 0.0; /* initialize for good order */_x000D_
      y_now[j] = y_l+(j*dx)*(y_r-y_l)/(x_r-x_l); /* line that satisfies BCs */_x000D_
      y_new[j] = y_l+(j*dx)*(y_r-y_l)/(x_r-x_l); /* line that satisfies BCs */_x000D_
      f_now[j] = 0.0; /* initialize for good order */_x000D_
   }_x000D_
_x000D_
   /* now dump the initial function and its half-step velocity to the Dat file */_x000D_
   for (j=0; j<=mm; j++) {_x000D_
      fprintf(f_dat, "%e %e %en", j*dx, y_new[j], (y_new[j]-y_now[j])/dt);_x000D_
   }_x000D_
   fprintf(f_dat, "n");_x000D_
   fflush(f_dat);_x000D_
_x000D_
   /* Prepare for time-step loop */_x000D_
_x000D_
   /* set coefficients for method -- see below */_x000D_
   c1 = 2.0*(1.0-dt*dt/(dx*dx));_x000D_
   c2 = dt*dt/(dx*dx);_x000D_
   c4 = dt*dt;_x000D_
_x000D_
   /* enter the discrete-time loop of the finite difference map */_x000D_
   for (n = 1; n < n_dt; n++) {_x000D_
      /* reset solution for new time step */_x000D_
      for (j=1; j<mm; j++) {_x000D_
         y_pre[j] = y_now[j];_x000D_
         y_now[j] = y_new[j];_x000D_
      }_x000D_
      /* calculate function f */_x000D_
      for (j=1; j<mm; j++) {_x000D_
         f_now[j] = func(eta, y_now[j]);_x000D_
      }_x000D_
      norm1 = 0.0;_x000D_
      norm2 = 0.0;_x000D_
      /* do the time step */_x000D_
      for (j=1; j<mm; j++) {_x000D_
         y_new[j] = c1*y_now[j]+c2*(y_now[j-1]+y_now[j+1])-y_pre[j]+c4*f_now[j];_x000D_
         norm1 += fabs(y_new[j]-y_now[j]);_x000D_
         if (fabs(y_new[j]-y_now[j]) > norm2) norm2 = fabs(y_new[j]-y_now[j]);_x000D_
      }_x000D_
      norm1 /= dt*mm;_x000D_
      norm2 /= dt;_x000D_
      _x000D_
      tn = t0+n*dt; /*time updated */_x000D_
_x000D_
      if (norm1 < 1.0e-10) n=n_dt; /* finish early if tolerance is met */_x000D_
   }_x000D_
   _x000D_
   for (j=0; j<=mm; j++) {_x000D_
      fprintf(f_dat, "%e %e %en", j*dx, y_new[j], (y_new[j]-y_now[j])/dt);_x000D_
   }_x000D_
   fprintf(f_dat, "n");_x000D_
   fprintf(f_dat, "%e %e %en", tn, norm1, norm2);_x000D_
   fprintf(stdout, "time=%e, norm1=%e, norm2=%en", tn, norm1, norm2);_x000D_
   fflush(f_dat);_x000D_
_x000D_
   fclose(f_dat);_x000D_
}_x000D_
_x000D_
/* the right-hand side function f */_x000D_
double func(eta, y)_x000D_
double y, eta;_x000D_
{_x000D_
   double f;_x000D_
_x000D_
   f = -sin(y)+eta;_x000D_
_x000D_
   return f;_x000D_
}

Do you need help with this or a different assignment? We offer CONFIDENTIAL, ORIGINAL (Turnitin/LopesWrite/SafeAssign checks), and PRIVATE services using latest (within 5 years) peer-reviewed articles. Kindly click on ORDER NOW to receive an A++ paper from our masters- and PhD writers.

Get a 15% discount on your order using the following coupon code SAVE15


Order a Similar Paper Order a Different Paper