Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

solve using matlab codes data : Problem 5: (20 points) Download the data file In

ID: 644335 • Letter: S

Question

solve using matlab codes

data :

Problem 5: (20 points) Download the data file InClass7P5_data.dat and save it into the same directory that you run your MATLAB scripts. The file contains simulated experimental data in three columns, x, exp(x) and x^2 with random noise added. Write your own script to open and read the data, using: (a) fgetl function (b) fscanf function (c) textscan function and then, plot the experimental data in two subplots (in 2 rows and 1 column), one for exp(x) and the other for x^2. In each subplot, also plot the theoretical curve (exp(x) or x^2) within the same range as in the experimental data. Make sure you properly label the axes, use reasonable font sizes, and include the right legends.

Explanation / Answer

in_file = fopen('file.dat', 'r'); // read only

if (in_file == -1)
error('oops, file can''t be read');
end
//graph for x and exp(x)
xlabel('x');
ylabel('exp(x)');
title('Graph between x and exp(x)');

[x, exp(x),xsquare,count] = fscanf(file, '%d','%d','%d', 1);
plot(x,exp(x),'o');
while (count == 1) % while we have read a number
[x, exp(x),xsquare,count] = fscanf(file, '%d','%d','%d', 1);
plot(x,exp(x),'o');
end
//graph for x and x^2
xlabel('x');
ylabel('x^2');
title('Graph between x and x^2');

[x, exp(x),xsquare,count] = fscanf(file, '%d','%d','%d', 1);
plot(x,xsquare,'o');
while (count == 1) % while we have read a number
[x, exp(x),xsquare,count] = fscanf(file, '%d','%d','%d', 1);
plot(x,xsquare,'o');
end