MATLAB是什么想必大家都知道,MATLAB是怎么一回事呢?
解方程想必大家都知道,解方程是怎么回事呢?就是这样。
牛顿前插
function qiancha = qiancha(x0)
x = 0:0.1:0.5;
y = cos(x);
n = 6;
T = zeros(n,n);
for i = 1:n
T(i,1) = y(i);
end
for i = 2:n
for j = 2:i
T(i,j) = T(i,j-1)-T(i-1,j-1);
end
end
disp(T);
sum = y(1);
t = (x0-x(1))/0.1;
pro = 1;
for i = 1:n-1
pro = pro * (t-i+1)/i;
sum = sum + T(i+1,i+1)*pro;
disp(pro);
disp(sum);
end
qiancha = sum;
Hermit
function result = Hermit(x0)
x = 0:0.1:0.5;
y = cos(x);
y1 = -sin(x);
n=6;
for i = 1:n-1
if x0 >x(i) && x0 < x(i+1)
xk = x0-x(i);
xk1 = x0-x(i+1);
kk1 = x(i)-x(i+1);
k1k = -kk1;
r1 = y(i)*(1+2*xk/k1k)*(xk1/kk1)^2;
r2 = y(i+1)*(1+2*xk1/kk1)*(xk/k1k)^2;
r3 = y1(i)*xk*(xk1/kk1)^2;
r4 = y1(i+1)*xk1*(xk/k1k)^2;
result = r1+r2+r3+r4;
break;
end
end
end
列高斯
clc
A=[4,2,0;4,4,2;2,2,3];
b=[2;4;6];
n=size(A,1);
for i=1:n-1
for j=(i+1):n
z=max(abs(A(i:n,i)));
p=find(abs(A(:,i))==z);
p=p(1);
t=A(i,:);
A(i,:)=A(p,:);
A(p,:)=t;
t=b(i);
b(i)=b(p);
b(p)=t;
m=A(j,i)/A(i,i);
A(j,:)=A(j,:)-A(i,:)*m;
b(j)=b(j)-b(i)*m;
end
end
x=zeros(n,1);
for i=n:-1:1
sum=A(i,:)*x;
x(i)=(b(i)-sum)/A(i,i);
end
disp(x);