How to fit the data with passing specific point and specific function

Please could you me some tips for the below question
To do the fitting, I have searched the polyfit and curve fitting. but i could find the fitting method like below
I would like fit the data by using the specific function like below
y= A (x^2) (x-1)^2 ( I want find A and the function should pass (0,0) and (1,0))
and data is like this:
x=[0 0.166666667 0.333333333 0.5 0.666666667 0.833333333 1]
y=[0 1.09162 1.71904 2.52173 1.20849 2.47433 0]
Therefore, from the data , I would like to get A values from y= A (x^2) (x-1)^2 and data point
And here is constraints that the fiiting function must pass the (0,0) and (1,0)
for example like this:

 Akzeptierte Antwort

KSSV
KSSV am 16 Nov. 2021
Bearbeitet: KSSV am 16 Nov. 2021
x=[0 0.166666667 0.333333333 0.5 0.666666667 0.833333333 1]' ;
y=[0 1.09162 1.71904 2.52173 1.20849 2.47433 0]' ;
n = 3; % Degree of polynomial to fit
V(:,n+1) = ones(length(x),1); % Vandermonde matrix
for j = n:-1:1
V(:,j) = x.*V(:,j+1);
end
% Constraints
Aeq = x([1 end]).^(n:-1:0);
beq = [y(1) y(end)];
p = lsqlin(V, y,[],[],Aeq,beq);
Minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
xnew = linspace(x(1),x(end)) ;
ynew = polyval(p,xnew);
plot(x,y,'.b-')
hold on
% Plot constraints
plot(x([1 end]),y([1 end]),'gx','linewidth',4)
% Plot fitted data
plot(xnew,ynew,'r','linewidth',2)
hold off

3 Kommentare

Thanks so much KSSV
your reply would be a good! guide to me .
Could I ask something more?
In your code red line is fitted line.
But, that i want to know is A value from y= A (x^2) (x-1)^2 < 4th polynomial
y= A( x^4 - 2x^2 + x^2)
the fitted line shoul be y= A (x^2) (x-1)^2 format
because I will use this shpae of function y= A (x^2) (x-1)^2
If A would be calculated , then i use this function format with calculated A.
I highly appreciate your reply!
Thanks
Could I get A value by keeping the the shape of A(x^2)*(x^2-1) like below ?
the shpae is symmetry at the center of x=0.5 (this graph has A=5 as an example)
As of now I have no idea. Will think over it and get back.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 16 Nov. 2021

Kommentiert:

am 17 Nov. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by