【发布时间】:2011-12-07 05:52:18
【问题描述】:
如何编写一个函数,该函数具有 3 个输入(由系数 [a b c] 和 x 值的向量组成的 2 个向量)的两个直线方程,其形式为 ax+by=c,输出一个向量,给出点的 x 和 y 值交点。
示例:solveSystem([1 -1 -1],[3 1 9],-5:5 ) 应该产生 [2 3]
到目前为止:
function coeff=fitPoly(mat)
% this function takes as an input an nx2 matrix consisting of the
% coordinates of n points in the xy-plane and give as an output the unique
% polynomial (of degree <= n-1) passing through those points.
[n,m]=size(mat); % n=the number of rows=the number of points
% build the matrix C
if m~=2
fprintf('Error: incorrect input');
coeff=0;
else
C=mat(:,2); % c is the vector of y-coordinates which is the 2nd column of mat
% build the matrix A
for i=1:n
for j=1:n
A(i,j)=(mat(i,1))^(n-j);
end
end
coeff=inv(A)*C;
end
【问题讨论】:
-
ax+bx=c 不是直线方程。你是说 ax+bu=c 吗?
-
您置顶的问题与您发布的代码不一致。您是在寻找线的交点还是多项式拟合。你应该澄清你的问题。
-
我想用它来创建向量的输入。一个用于我的 x 值、y 值和系数,