Fitting equation to data points

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

 采纳的回答

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 个评论

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 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by