1 view (last 30 days)

Hi All,

I would like to make a convex curve from this (x,y) data that I have. The curve must connect the first and last points of y.

x= 7000,7050,7100,7150,7200

y= -92.9,-125.6,-158.5,-190.9,-223.5

The help would be apprecited,

Thanks in advance,

Riyadh

David Goodmanson
on 8 Feb 2020

Edited: David Goodmanson
on 8 Feb 2020

Riyadh;

The differences from a straight line are small, so it make sense to look at that difference.

x = [7000,7050,7100,7150,7200]'

y = [-92.9,-125.6,-158.5,-190.9,-223.5]'

ylin = linspace(y(1),y(end),5)'

ydiff = y - ylin;

figure(1)

plot(x,ydiff,'o-');

grid on

The three differences are all negative, so absent any other information it can just be fit with a parabola that is zero at the end points. This will lead to a curve that is convex downwards.

p = (x-x(1)).*(x-x(end)); % parabola, zero at end points

c = p\ydiff; % least squares fit

xnew = linspace(7000,7200,500); % grid with more points

ydiffnew = c*(xnew-x(1)).*(xnew-x(end)); % fitted parabola, zero at end points

figure(2)

plot(x,ydiff,'o-',xnew,ydiffnew)

grid on

Then the final result ynew is this plus the linear line

slope = (y(end)-y(1))/(x(end)-x(1));

ylinnew = y(1) + slope*(xnew-x(1));

ynew = ylinnew + ydiffnew;

figure(3)

plot(x,y,'o-',xnew,ynew)

grid on

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 7 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/504119-how-can-i-make-curve-form-data#comment_794452

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/504119-how-can-i-make-curve-form-data#comment_794452

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/504119-how-can-i-make-curve-form-data#comment_794463

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/504119-how-can-i-make-curve-form-data#comment_794463

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/504119-how-can-i-make-curve-form-data#comment_794549

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/504119-how-can-i-make-curve-form-data#comment_794549

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/504119-how-can-i-make-curve-form-data#comment_794825

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/504119-how-can-i-make-curve-form-data#comment_794825

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/504119-how-can-i-make-curve-form-data#comment_794827

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/504119-how-can-i-make-curve-form-data#comment_794827

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/504119-how-can-i-make-curve-form-data#comment_794830

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/504119-how-can-i-make-curve-form-data#comment_794830

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/504119-how-can-i-make-curve-form-data#comment_794836

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/504119-how-can-i-make-curve-form-data#comment_794836

Sign in to comment.