拟合和绘制抛物线,matlab [英] fitting and plotting a parabola, matlab

查看:304
本文介绍了拟合和绘制抛物线,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);

如何在matlab中求解系数(a,b,c)并绘制该曲线?

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

推荐答案

重新排列y = f(x)以使a,b和c为未知数:

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;

这描述了当您替换三个成对的x和y值时,a,b和c中的线性方程组的系统.

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]

现在您有了系数a,b和c,因此可以绘制函数.

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

要绘制函数,请首先选择数据点的x值

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

xt = 1:100;

然后计算y值(假设您已经有a,b,c)

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);

阅读有关绘图功能的Matlab帮助,以自定义绘图样式.

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

这篇关于拟合和绘制抛物线,matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆