curve fitting tool plot is different from my plot

1 vue (au cours des 30 derniers jours)
Paris Pasqualin
Paris Pasqualin le 15 Juin 2021
Commenté : Paris Pasqualin le 15 Juin 2021
Dear all,
I want to correlate y to x through the curve fitting tool by using a Power2 equation: f(x) = a*x^b+c
x = [1.34673 1.35171 1.3531 1.35402 1.35636 1.35875 1.3608 1.36278 1.36491 1.36728 1.36855 1.37048 1.37468 1.37505 1.37507 1.37917 1.38045 1.38387 1.38449 1.38473 1.38898 1.39084 1.3925 1.39367 1.39505 1.39716 1.39903 1.40043 1.4022 1.40435 1.40562 1.40767 1.40918 1.41063 1.41219 1.41371 1.41533 1.41688 1.41856 1.4197 1.42117 1.42366 1.42503 1.4265 1.42797 1.4293 1.4306 1.432 1.43331 1.43479 1.437 1.43919 1.4416 1.44366 1.44573];
y = [10.41769233 11.9053698 13.1164268 14.25963171 15.00649903 16.35618123 17.45629085 18.49632079 19.61280955 20.63621936 21.69999059 22.64564288 23.56982874 24.47325866 25.41513541 26.47571957 27.50695474 28.56386269 29.46143426 30.3373697 31.04306928 31.78480751 32.53522304 33.29272229 33.98758977 34.84724419 35.51048907 36.16058495 36.79791688 37.42285508 38.07618905 38.65659969 39.24568484 39.82374683 40.35343406 40.91105232 41.47658408 42.04911521 42.61072281 43.12758811 43.63750215 44.4509815 44.93754224 45.39985008 45.91731273 46.36414975 46.80366364 47.26624048 47.66262453 48.12476471 48.83962785 49.53505656 50.21183273 50.87069688 51.4912325];
I tried to plot plot f(x) with the a,b,c values from the curve fitting tool results, but my curve is different from the one I see in the automatic plot.
Has anyone else had the same problem?
Best regards,
Paris
  1 commentaire
Paris Pasqualin
Paris Pasqualin le 15 Juin 2021
I understand my mistake now, thanks for the answers

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 15 Juin 2021
Modifié(e) : Star Strider le 15 Juin 2021
I haven’t.
Try this, and compare it with your (unposted) code —
x = [1.34673 1.35171 1.3531 1.35402 1.35636 1.35875 1.3608 1.36278 1.36491 1.36728 1.36855 1.37048 1.37468 1.37505 1.37507 1.37917 1.38045 1.38387 1.38449 1.38473 1.38898 1.39084 1.3925 1.39367 1.39505 1.39716 1.39903 1.40043 1.4022 1.40435 1.40562 1.40767 1.40918 1.41063 1.41219 1.41371 1.41533 1.41688 1.41856 1.4197 1.42117 1.42366 1.42503 1.4265 1.42797 1.4293 1.4306 1.432 1.43331 1.43479 1.437 1.43919 1.4416 1.44366 1.44573];
y = [10.41769233 11.9053698 13.1164268 14.25963171 15.00649903 16.35618123 17.45629085 18.49632079 19.61280955 20.63621936 21.69999059 22.64564288 23.56982874 24.47325866 25.41513541 26.47571957 27.50695474 28.56386269 29.46143426 30.3373697 31.04306928 31.78480751 32.53522304 33.29272229 33.98758977 34.84724419 35.51048907 36.16058495 36.79791688 37.42285508 38.07618905 38.65659969 39.24568484 39.82374683 40.35343406 40.91105232 41.47658408 42.04911521 42.61072281 43.12758811 43.63750215 44.4509815 44.93754224 45.39985008 45.91731273 46.36414975 46.80366364 47.26624048 47.66262453 48.12476471 48.83962785 49.53505656 50.21183273 50.87069688 51.4912325];
a = -1300;
b = -9.032;
c = 98.01;
y_fit = a.*x.^b + c;
figure
plot(x, y, '.')
hold on
plot(x, y_fit, '-r')
hold off
grid
EDIT — (15 Jun 2021 at 14:30)
This is strange, I ploted as:
x_vet = [1.3467 1.4457];
a = -1300;
b = -9.032;
c = 98.01;
y = @(x) a.*x.^b+c;
plot(x_vet,y(x_vet),'k')
Not at all strange.
That code calculates only 2 points, so it only plots 2 points and the values fitted to them.
.

Plus de réponses (2)

John D'Errico
John D'Errico le 15 Juin 2021
I predict there will be no problem here. So let me see what you MAY have done wrong. I say may, since we do not see how you created that plot. First, let me see what the CFTB does on its own.
x = [1.34673 1.35171 1.3531 1.35402 1.35636 1.35875 1.3608 1.36278 1.36491 1.36728 1.36855 1.37048 1.37468 1.37505 1.37507 1.37917 1.38045 1.38387 1.38449 1.38473 1.38898 1.39084 1.3925 1.39367 1.39505 1.39716 1.39903 1.40043 1.4022 1.40435 1.40562 1.40767 1.40918 1.41063 1.41219 1.41371 1.41533 1.41688 1.41856 1.4197 1.42117 1.42366 1.42503 1.4265 1.42797 1.4293 1.4306 1.432 1.43331 1.43479 1.437 1.43919 1.4416 1.44366 1.44573];
y = [10.41769233 11.9053698 13.1164268 14.25963171 15.00649903 16.35618123 17.45629085 18.49632079 19.61280955 20.63621936 21.69999059 22.64564288 23.56982874 24.47325866 25.41513541 26.47571957 27.50695474 28.56386269 29.46143426 30.3373697 31.04306928 31.78480751 32.53522304 33.29272229 33.98758977 34.84724419 35.51048907 36.16058495 36.79791688 37.42285508 38.07618905 38.65659969 39.24568484 39.82374683 40.35343406 40.91105232 41.47658408 42.04911521 42.61072281 43.12758811 43.63750215 44.4509815 44.93754224 45.39985008 45.91731273 46.36414975 46.80366364 47.26624048 47.66262453 48.12476471 48.83962785 49.53505656 50.21183273 50.87069688 51.4912325];
mdl = fittype('a*x.^b + c','indep','x');
estmdl = fit(x',y',mdl,'start',[-1000 -9 100])
estmdl =
General model: estmdl(x) = a*x.^b + c Coefficients (with 95% confidence bounds): a = -1300 (-1522, -1079) b = -9.032 (-9.805, -8.26) c = 98.01 (92.48, 103.5)
So it looks as it the estimated fit is the same as yours.
plot(estmdl)
hold on
plot(x,y,'bo')
The fit seems good enough, passing through the data nicely. Now, let me plot the fit myself.
figure
plot(x,y,'bo',x,estmdl.a*x.^estmdl.b + estmdl.c)
I don't see the problem. What you may have done to produce the straight line there is just wild random conjecture. As much as I try to read your mind, or to see inside your computer, I get nothing.

Steven Lord
Steven Lord le 15 Juin 2021
Show us the code you used to create your plot.
Did you use the full double precision values of the coefficients stored in the fit object (obtained using the coeffvalues function) or did you use the approximations printed out in the results windows?
In some cases the decimal places that aren't printed are irrelevant. If you wanted to know if a coefficient was greater than 1 and the displayed value was 0.001 then you don't need to know the places after the 1 to get the answer. But in some cases they are very relevant like if the displayed coefficient is 1.0000 -- is that actually 0.99999999 or 1.000000001?
format short
x = [0.99999999; 1.000000001]
x = 2×1
1.0000 1.0000
In your particular example, a slight change in the exponent can result in a significant change in the answer. Using roughly the values you have for a and b and the x coordinate around where you see a difference in your plots:
y1 = 1000*(1.37^(-9))
y1 = 58.8186
y2 = 1000*(1.37^(-9.01))
y2 = 58.6338

Catégories

En savoir plus sur Descriptive Statistics dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by