
Ryan D. answered 07/05/23
PhD in Engineering with 10+ Years MATLAB Experience
%% define known data points
x = [1.6 2 2.5 3.2 4 4.5]; %x
fx = [2 8 14 15 8 2]; %f(x)
%% use interp1 function to estimate unknown data point
help interp1 %read help to learn about how interp1 function works and what arguments it expects
q =2.8; %point to evaluate
fq = interp1(x,fx,q); %interpolated estimate of f(q)
%% display results
disp(['f(',num2str(q),') = ',num2str(fq)]); %display answer to user
figure; plot(x,fx,'ko--'); hold on; plot(q,fq,'r*'); %plot results to check validity
xlabel('x'); ylabel('f(x)'); %add labels