Hello,
I have the data points
x = [22.96, 88.2, 114.275, 85.3] y = [0.1422, 0.157967, 0.202167, 0.1612]
and I want to fit the equations
y =(L/Vr)-((L/4.316)*cosd(x))
to determine the value of L and Vr.
L should be in the range from 0.0 - 1.7
Vr should be in the range from 2.0 - 6.0
Can anyone help?
Thank you

 채택된 답변

Star Strider
Star Strider 2018년 3월 14일

1 개 추천

Try this:
fy = @(L,Vr,x) (L./Vr)-((L./4.316).*cosd(x));
x = [22.96, 88.2, 114.275, 85.3];
y = [0.1422, 0.157967, 0.202167, 0.1612];
B = fmincon(@(b) norm(y - fy(b(1),b(2),x)), [1; 4], [],[],[],[],[0 2],[1.7 6.0])
fprintf('L = %.15f\nVr = %.15f\n', B)
xv = linspace(min(x), max(x));
figure(1)
plot(x, y, 'pg')
hold on
plot(xv, fy(B(1),B(2),xv), '-r')
hold off
grid
L = 0.347528298961989
Vr = 2.000000558931784

댓글 수: 2

Joel Lowe
Joel Lowe 2018년 3월 26일
Hello again,
Thank you for your answer. Is there a way of outputting the residual misfit?
Thanks
My pleasure.
Calculate the residuals as:
resid = y - fy(B(1),B(2),x);
The objective function calculates the norm of the residuals, so if you want those as well, ask fmincon for fval:
[B, resnorm] = fmincon(@(b) norm(y - fy(b(1),b(2),x)), [1; 4], [],[],[],[],[0 2],[1.7 6.0])
so ‘resnorm’ has the norm of the residuals.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Least Squares에 대해 자세히 알아보기

질문:

2018년 3월 14일

댓글:

2018년 3월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by