# curve fitting using least square method form equation , y = (1 + a sin(2x))/ (b + cx^2) where a, b, c are unknown real constants.

7 views (last 30 days)
Parva on 7 Feb 2023
Commented: John D'Errico on 7 Feb 2023
hi, this is the question:This file contains data points (xi , yi) where xi is the i-th entry of array x and yi is the i-th entry of array y. It is known that the dependence between y and x is of the form equation (1) , y = (1 + a sin(2x))/ (b + cx^2) where a, b, c are unknown real constants. It is known that all data points (xi , yi) satisfy equation (1) up to small measurement errors. Clear the denominator in equation (1) and consider plugging in each data point. This leads to an overdetermined system of linear equations. Use Matlab's least-squares solver \ to find the least-squares approximate solution to this overdetermined system of linear equations. You must not use any for-loops or while-loops.
I don't know what I am doing wrong in this code:
clear; close all; format compact
n = length(x);
A = [sin(2*x(:)), x(:).^2, ones(length(x),1)];
b = y(:);
sol = A\b;
% Extract the coefficients a, b and c
a = sol(1)
c = sol(2)
b= sol(3)

John D'Errico on 7 Feb 2023
Hint (since this is homework): What is your model? WRITE IT DOWN. What happens when you mutiply by the term in the denominator? WRITE IT DOWN.
##### 1 CommentShowHide None
John D'Errico on 7 Feb 2023
Since you accepted my answer, I hope you saw the error you made. It should have been aparent when you did what I said.

### Categories

Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by