Question: 1 ) discretize space and time ( 1 0 points ) - space variable x: start value 0 , end value 1 0 e -

1) discretize space and time (10 points)
- space variable x: start value 0, end value 10e-3, interval 1e-5
- time variable t : start value 0, end value 1e-4, number of points 101
2) generate data (10 points)
compute values for p for each location and each time instance
recall:
- all locations are stored in the array x created in 1)
- all time instances are stored in the array t created in 1)
to generate the data and store it in a 2d array p follow these steps:
- allocate and initialize a 2d array called p with as many rows as you
have points in space and as many columns as you have time instances
- loop over all time instances and at each time instance loop over all x
locations (hint: nested loops)
- use the loop variable it for looping over
the time instances and loop variable i for the loop over the x locations
- for each it and i compute p(i,it) as
p = exp(100*x)*cos(2*pi/(xe-xs)*10*x-2*pi*100e3*t)
+ exp(50*x)*cos(2*pi/(xe-xs)*5*x-2*pi*50e3*t)
+ cos(2*pi/(xe-xs)*12*x-2*pi*150e3*t)
+ exp(-50*x)*cos(2*pi/(xe-xs)*20*x-2*pi*200e3*t)
3) write data to file (10 points)
write the data in binary format to a file with the name data.bin
write the data in the following format
column 1: x
columm 2: t
column 3: p
write out the data in double precision format
note: p had nt columns, only write nt-1 columns to the file
4) visualize data (15 points)
generate a subplot with 2 rows (2 figures in total)
in the first row plot the values of p for i =1 over time
in the second row plot the values of p for it =1,26,51 and 76 over x
customize the plots as follows
- increase the linewidth to 2 pts
- set the font size to 20
- switch on the grid
- for the plot in row 1:
* set the x-axis label to t and the y-axis label to p
* set the x-axis limits from 0 to 1e-4
* set the y-axis limits from -2 to 4
- for the plot in row 2:
* set the x-axis label to x and the y-axis label to p
* set the x-axis limits from 0 to 1e-2
* set the y-axis limits from -5 to 10
* add a legend to the figure with the labels '1','26','51' and '76'
for the four curves plotted in this graph
- generate a figure file named project_03_matlab_figure.png
Matlab Code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!