Write a function that will receive data points in the form of x and y vectors. If the lengths of the vectors are not the same, then they can’t represent data points so an error message
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:14| Question number:18.14
All Answers
total answers (1)
ranCurveFit.m
function ranCurveFit(x,y)
% Uses x,y input data vectors, performs a curve fit with a random
% polynomial degree. Function terminates if input vectors
% have different lengths.
% Format of call: ranCurveFit(x,y)
% Does not return any values
if length(x) ~= length(y)
disp('Error! x and y must have the same length')
else
n = randi([1,length(x)-1]);
coefs = polyfit(x,y,n);
curve = polyval(coefs,x);
plot(x,y,'ko',x,curve)
title(sprintf('Polynomial degree: %d',n))
end
end
need an explanation for this answer? contact us directly to get an explanation for this answer