필터 지우기
필터 지우기

Fit data with a given equation for 3 variables

조회 수: 7 (최근 30일)
Tesla
Tesla 2022년 5월 24일
댓글: Tesla 2022년 5월 24일
I want to fit my data to the following equation, but I dont know how to force the program to take the b values which i have, instead of calculating them automatically, I attached here my code which i wrote
fy = @(a,b,x) ((1-(x/a)).^(-a*b));
x = [0,0.1, 0.2, 0.3, 0.4, 0.46, 0.55, 0.6];
y = [0.001, 0.00111499, 0.0011926, 0.0013699, 0.00161633, 0.00192075, 0.00274991, 0.00357156];
b = [0, 1.1499, 0.963, 1.233, 1.540825, 2.001630435, 3.181654545, 4.285933333];
B = fmincon(@(c) norm(y - fy(c(1),c(2),x)), [1; 1], [],[],[],[], [0 0],[1 90]);
fprintf('PhiMax = %.15f\nVisco = %.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
  댓글 수: 2
Torsten
Torsten 2022년 5월 24일
How should it be possible to have the value for b if you don't know the value for a ?
Tesla
Tesla 2022년 5월 24일
Indeed i am looking for the value of a

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

채택된 답변

Torsten
Torsten 2022년 5월 24일
편집: Torsten 2022년 5월 24일
Your function is not suited to reflect your data.
x = [0,0.1, 0.2, 0.3, 0.4, 0.46, 0.55, 0.6];
y = [0.001, 0.00111499, 0.0011926, 0.0013699, 0.00161633, 0.00192075, 0.00274991, 0.00357156];
b = [0, 1.1499, 0.963, 1.233, 1.540825, 2.001630435, 3.181654545, 4.285933333];
p0 = 1;
B = lsqnonlin(@(a)fy(a,x,y,b),p0,max(x),Inf)
fprintf('PhiMax = %.15f\nVisco = %.15f\n', B)
figure(1)
plot(x, y, 'pg')
hold on
plot(x, fy(B(1),x,y,b)+y, '-r')
hold off
grid
function res = fy(a,x,y,b)
res = ((1-(x/a)).^a).^b - y;
end
  댓글 수: 1
Tesla
Tesla 2022년 5월 24일
Thanks a lot, it works, I just need to multipy the function by 0.001.
function res = fy(a,x,y,b)
res = 0.001*((1-(x/a)).^a).^b - y;
end

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

추가 답변 (1개)

Hiro Yoshino
Hiro Yoshino 2022년 5월 24일
How about this?
You only need to think about c as follows:
fy = @(a,b,x) ((1-(x/a)).^(-a*b));
x = [0,0.1, 0.2, 0.3, 0.4, 0.46, 0.55, 0.6];
y = [0.001, 0.00111499, 0.0011926, 0.0013699, 0.00161633, 0.00192075, 0.00274991, 0.00357156];
b = [0, 1.1499, 0.963, 1.233, 1.540825, 2.001630435, 3.181654545, 4.285933333];
B = fmincon(@(c) norm(y - fy(c,b,x)),1,[],[],0,1)
Converged to an infeasible point. fmincon stopped because the size of the current step is less than the value of the step size tolerance but constraints are not satisfied to within the value of the constraint tolerance. Consider enabling the interior point method feasibility mode.
B = 6.6511e+03
  댓글 수: 1
Tesla
Tesla 2022년 5월 24일
Thank you for the suggestion but the fitting plot is not working

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

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by