开发者

fitting and plotting a parabola, matlab

I have a very simple problem. I have

x=[ 10 25 50];
y=[ 1.2 3 7.5];

I know my curve fitting function

开发者_高级运维
f(x)=(a*x+1)/(bx+c);

How can I get coefficient(a,b,c) solve in matlab and also plot this curve?


Rearrange y = f(x) to make a, b, and c the unknowns:

y = (ax + 1) / (bx + c)
y(bx + c) = ax + 1
ax - bxy - cy = -1;

This describes a system of simultaneous linear equations in a, b, and c when you substitute your three paired values of x and y.

x      = [10, 20, 100];
y      = [1.2, 0.7, 0.4];
coeffs = [x', (-x.*y)', -y'];
knowns = [-1, -1, -1]';

v      = coeffs \ knowns;        % v is [a; b; c]

Now you have the coefficients a, b, and c so you can plot the function.

Addendum: plotting

To plot a function, first choose the x-values of the data points

xt = 1:100;

Then calculate the y-values (assuming you've already got a, b, c)

yt = (a*x + 1) ./ (b*x + c)

Then just plot them!

plot(xt, yt);

Read the Matlab help on the plot function for customizing the style of the plot.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜