Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The file below contains five data points plus additional data. The data is at the beginning of the lines, delimited by whitespace. After the data,

The file below contains five data points plus additional data. The data is at the beginning of the lines, delimited by whitespace. After the data, there will be some explanation as to the meaning of the data. The explanations might not be the same as that shown here, but the order of the lines will always be the same: numbers at the beginning of the line and explanations at the end.

-4 -7.6 Point 1 -2 -17.2 Point 2 0.2 9.2 Point 3 1 -1.6 Point 4 4 -36.4 Point 5 1 xmin 3 xmax 0.2 increment in x

The graph of the function ( ) will pass through all five points if the constants a, b, c, d and e are chosen correctly. After the constants are known, other points along the polynomial can be found by plugging any value of x into the function. For example, an output file could be created containing a table of x and y values that lie on this function: X Y 1.0000 2.1234 1.2000 3.2834 . . . . . . 3.0000 3.4234

Write a Matlab script to prompt for the input filename, open it and read it. Determine the constants a, b, c, d and e. Construct a vector of x values from xmin to xmax by the increment in x. Determine a y value for each value in the x vector, such that the y values fall on the function. Prompt for an output filename and write your data into the output file. You must have X and Y headings as shown above and the data must be neatly aligned under the headings. Use columns that are 15 characters wide, with 4 digits after the decimal point. Use one space between the columns. Please note that I have an input file with secret numbers that I will use for testing your script. Your script should do its work silently: it will prompt for the filenames, but nothing should be written to the screen after the prompts are issued.

So I did this, is it ok(how would you fix it)

filename=input('enter file name: ','s');

fid=fopen(filename,'r')';

A=fscanf(fid,'%f ',fgetl(fid),[1 inf])';

B=fscanf(fid,'%f ',fgetl(fid),[2 inf])';

C=fscanf(fid,'%f ',fgetl(fid),[3 inf])';

D=fscanf(fid,'%f ',fgetl(fid),[4 inf])';

E=fscanf(fid,'%f ',fgetl(fid),[5 inf])';

xmin=fscanf(fid,'%s',fgetl(fid),1);

xmax=fscanf(fid,'%s',fgetl(fid),1);

increment=fscanf(fid,'%f',1);

fclose(fid);

%X's put in matrix

X1=A(1);

X2=B(1);

X3=C(1);

X4=D(1);

X5=E(1);

matrix=[X1,X2,X3,X4,X5]';

%Y's put in matrix

Y1=A(2);

Y2=B(2);

Y3=C(2);

Y4=D(2);

Y5=E(2);

matrix2=[Y1;Y2;Y3;Y4;Y5];

e = [matrix.^4 matrix.^3 matrix.^2 matrix ones(5,1)];

X=e\matrix2;

x_v=xmin:increment:xmax';

xmain = [x_v.^4; x_v.^3; x_v.^2; x_v; ones(1,41)];

Yvalues = X'*xmain;

list=[x_v' Yvalues']

fprinf('%f %f ',list');

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

=+ What topics should be provided in training programs?

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago