Linear least-squares fit
1 view (last 30 days)
Show older comments
Hello, I'm trying to find the least squares fit between two sets of data but all the examples I've seen are for one set. Would anyone mind helping me? Please and thank you!
Code:
%%Part 2
% Graph: Transducer & Scannivalve vs Manometer
x1 = [.054 .107 .177 .272 .383 .514 .809]; %transducer (V)
x2 = [.162 .306 .495 .749 1.051 1.402 2.193]; %scannivalve (V) - switched to +
y = [.182 .47 .841 1.349 1.945 2.615 4.241]; %manometer (in. of H20)
figure(1)
plot(x1,y,'x',x2,y,'o');
title('Part 2'); xlabel('Voltage, V');
ylabel('Pressure, P'); grid on
legend('Tansducer','Scannivalve');
0 Comments
Answers (1)
Star Strider
on 9 Sep 2015
See if this does what you want:
dsnmtx = [ones(size(y',1),1) x1' x2']; % Design Matrix
B = dsnmtx\y'; % Estimate Parameters
yfit = [ones(size(y',1),1) x1' x2']*B; % Estimated ‘y’
figure(1)
stem3(x1', x2', y')
hold on
plot3(x1', x2', yfit)
hold off
grid on
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!