How to plot hyperbola curve to pints?
5 ビュー (過去 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))
0 件のコメント
採用された回答
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
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 Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!