How to plot hyperbola curve to pints?

2 次查看(过去 30 天)
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))

采纳的回答

Daniel Pollard
Daniel Pollard 2020-11-27
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 个评论
Daniel Pollard
Daniel Pollard 2020-11-27
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multibody Modeling 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by