Linear least-squares fit
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (1개)
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
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!