Linear least-squares fit

2 次查看(过去 30 天)
Alyssa
Alyssa 2015-9-9
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');

回答(1 个)

Star Strider
Star Strider 2015-9-9
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

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by