Linear least-squares fit
이전 댓글 표시
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
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
카테고리
도움말 센터 및 File Exchange에서 Linearization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!