How to plot hyperbola curve to pints?

5 ビュー (過去 30 日間)
captainjoker
captainjoker 2020 年 11 月 27 日
コメント済み: captainjoker 2020 年 11 月 27 日
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.
captainjoker
captainjoker 2020 年 11 月 27 日
Thank you very much sir!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by