How to plot hyperbola curve to pints?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
captainjoker
le 27 Nov 2020
Commenté : captainjoker
le 27 Nov 2020
Hello, I have the follwing data given:
x = [0.002 0.01 0.02 0.05 0.12 0.2]
y = [0.2309 3.1405 3.4832 4.0078 4.7561 4.833]
How can I Plot a curved hypobola? I have already tried follwing code but my curve is still edgy and not curved:
hyprb = @(b,x) b(1) + b(2)./(x + b(3)); % Generalised Hyperbola
NRCF = @(b) norm(y - hyprb(b,x)); % Residual Norm Cost Function
B0 = [1; 1; 1];
B = fminsearch(NRCF, B0); % Estimate Parameters
figure(1)
plot(x, y, 'pg')
hold on
plot(x, hyprb(B,x), '-r')
hold off
grid
text(0.7, 0.52, sprintf('y = %.4f %+.4f/(x %+.4f)', B))
0 commentaires
Réponse acceptée
Daniel Pollard
le 27 Nov 2020
You need more values in your vector x. Try it with
x0 = linspace(0.002, 0.2, 100);
and alter your code to be
hyprb = @(b,x) b(1) + b(2)./(x + b(3)); % Generalised Hyperbola
NRCF = @(b) norm(y - hyprb(b,x)); % Residual Norm Cost Function
B0 = [1; 1; 1];
B = fminsearch(NRCF, B0); % Estimate Parameters
figure(1)
plot(x, y, 'pg')
hold on
plot(x0, hyprb(B,x0), '-r')
hold off
grid
text(0.7, 0.52, sprintf('y = %.4f %+.4f/(x %+.4f)', B)).
The green points have stayed the same, using your original x and y, but now the red curve has 100 points instead of six, so appears smoother.
3 commentaires
Daniel Pollard
le 27 Nov 2020
I don't have access to my Matlab machine at the moment, so this is just a stab in the dark but I think if you call
disp(B)
then I think you'll see the three parameters which you named b(1), b(2) and b(3) in the first line.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Multibody Modeling dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!