Ordinary Least Squares Method program
6 次查看(过去 30 天)
显示 更早的评论
I have to make form scratch a program that applies the Ordinary Least Squares Method to a set of data (matrix D) and the base functions( elements of the vector b), but the program isnt working, I think it's not creating the inline functions version of the base functions that I need to calculate the value of those functions on some points, but I don't know how to correct that:
function g=mmq(D,b)
[~,tc]=size(D);
syms x;
for i=1:length(b);
b(i)=inline(b(i));
end
l=1;
h=1;
A=zeros(length(b),length(b));
while l<=length(b);
for c=1:length(b);
while h<=tc;
A(l,c)=A(l,c)+(b(l)(D(1,h))*b(c)(D(1,h)));
h=h+1;
end
end
l=l+1;
end
Y=zeros(length(b));
for k=1:length(b);
while r<=tc;
Y(l)=Y(l)+(b(k)(D(1,r))*D(2,r));
r=r+1;
end
end
Y=Y';
C=A\Y;
for u=1:length(C);
g=g+(C(u)*b(u));
end
end
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!