Question about non linear experimental data fitting with one independent and two dependent variables
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello I have some experimental data and i am trying to find a relation between them.Because the measurement techniques for this field are not so advanced the data are not exactly in the curve.The non linear regression that is going to be used has two independent and one dependent variable(x and R is the independent and c is y the dependent as c(R,x)).where 0<x<12.The table of data is below.
C Log10(R)
4.0452 1.3169
4.0148 1.3169
4.0722 1.3400
4.1397 1.4399
3.8377 1.1000
3.9568 1.1323
2.1806 1.0000
2.5000 1.0000
2.2159 1.0000
4.1859 1.5300
4.1864 1.3700
4.1866 1.6700
4.1847 1.3600
Can anyone provide me with some guidelines to do the regression as i am new in matlab and i am not so fluent on how to use it in statistics? Thank you in advance
댓글 수: 0
답변 (1개)
Star Strider
2016년 4월 14일
NOTE — The title of your question is different from your Question. I went with the text of your question, not the title in my Answer.
——————————————————————————————————————————————————
It is relatively straightforward to do a nonlinear regression with two independent variables, but not immediately obvious. It’s necessary to create a matrix from the independent variables, and use the columns of the independent variable matrix within the function to use the independent variables where they are needed. I created a function to illustrate this, and then used fminsearch to do the regression. Note that the independent varaibles are in the ‘Xm’ matrix, and that I used each column separately in the objective function:
D = [ 4.0452 1.3169
4.0148 1.3169
4.0722 1.3400
4.1397 1.4399
3.8377 1.1000
3.9568 1.1323
2.1806 1.0000
2.5000 1.0000
2.2159 1.0000
4.1859 1.5300
4.1864 1.3700
4.1866 1.6700
4.1847 1.3600];
D = [[0:12]' D]; % Create ‘D’ (Add ‘[0:12]'’ Vector)
Xm = D(:,1:2); % Independent Variable
R = 10.^D(:,3); % Dependent Variable
f = @(B,Xm) B(1).*sin(B(2).*Xm(:,1)+B(3)) + B(4).*Xm(:,2); % Create Model (Objective Function)
B0 = ones(4,1);
SSECF = @(B) sum((R - f(B,Xm)).^2); % Sum Squared Error Cost Function
[B_est,SSE] = fminsearch(SSECF, B0); % Estimate Parameters
figure(1)
plot3(D(:,1), D(:,2), 10.^D(:,3), 'bp')
hold on
plot3(D(:,1), D(:,2), f(B_est,Xm), '-r')
hold off
grid on
xlabel('X')
ylabel('Y')
I actually got a decent fit with my little function. I wish you the same with yours!
Make the appropriate changes to ‘B0’ for your function. (Mine has four parameters, so ‘B0’ has to have the same length.) If you call your function ‘f’, that is the only is probably the only change you will need to do to my code. The ‘SSE’ output from the fminsearch call is the sum-squared-error at convergence.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!