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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by