23.3k views
2 votes
In this problem, we want to represent the relationship between the input of a system, x, and its output, y, using a polynomial. A set of 21 system measurement data pairs were obtained and saved in the MATLAB file xyg1.mat.

To solve this problem, design and write a MATLAB function named polyfitsystem.m that has the following requirements:

1. The function must have the following input arguments:

a. x containing the input measurement data
b. y containing the output measurement data
c. R2 the minimum desired coefficient of determination resulting from the curve fitting calculations

2. The function must have the following output arguments:

a. z containing the coefficients of the fitting polynomial
b. N the degree of the polynomial
c. R2 the actual coefficient of determination resulting from the curve fitting calculations.

You may use the MATLAB built-in functions polyfit and polyval inside your user-defined function polyfitsystem.

To test your function, write a MATLAB script that calls your polyfitsystem function using the provided data and the following examples of minimum desired values for R2

User Cemal
by
6.1k points

1 Answer

2 votes

Answer:

clc

clear all

close all

format long

A=load('xyg1.mat');

x=A(:,1);

y=A(:,2);

[z,N,R2]=polyfitsystem(x,y,0.95)

function [z,N,R2]=polyfitsystem(x,y,R2)

for N=1:20

z=polyfit(x,y,N);

SSR=sum((y-polyval(z,x)).^2);

SST=sum((y-mean(y)).^2);

s=1-SSR/SST;

if(s>=R2)

R2=s;

break;

end

end

xx=linspace(min(x),max(x));

plot(x,y,'o',xx,polyval(z,x));

xlabel('x');

ylabel('y(x)');

title('Plot of y vs x');

end

Step-by-step explanation:

User Cald
by
6.0k points