《数值计算实验》word版

更新时间:2023-05-27 13:03:50 阅读: 评论:0

数 值 实 验
数值实验1  线性方程组求解
一、方法与程序
1.:带选主元的分解法ede(MATLAB程序)
Function x =lufact(A,b)
% Input  - A is an NN matrix
%      - b is N1 matrix
%Output  -x is an N1 matrix containing the solution to Ax=b
%Initialize x, y, the temporary storage matrix C, and the row
%permutation information matrix R
[N,N]=size(A);
x=zeros(N,1);
y=zeros(N,1);
c=zeros(N,1);
R=1:1;
For k=1:N-1
% Find the pivot row for colum p
[max1,j]=max (abs(A(p:N,p)));
% Interchange row p and j
  c=A(p,:);
A(p,:)=A(j+p-1,:);
A(j+p-1,:)=c;
D=R(p);
R(p)= R(j+p-1);
R(j+p-1)=d;
if a(p,p)==0
‘A is singular. No unique solution’
break
end
%Calculate multiplier and place in sundiagonal portion of A
For k=p+1:N
翻来覆去的说
  mult=A(k,p)/A(p,p);
A(p,:)=A(j+p-1,:);
A(k,p)=mult;
A(k,p+1:N)= A(k,p+1:N)-mult* A(p,p+1:N);
end
end
%solve for y
y(1)=b(R(1));
For k=2:N
  Y(k)=b(R(k))-A(k,1:k-1)*y(1:k-1)
end
grubby
%solve for x
x(N)=y(N)/A(N,N);
For k=N-1:-1:1
  x(k)=(y(k)-A(k,k+1:N)*x(k+1:N))/A(k,k);
end
二、数值试验内容
1)带选主元的分解法求解线性方程组,其中
使用MATLAB中的[L,U,P]=lu(A)命令检查得到的答案.
2)使用带选主元的分解法求解线性方程组,其中
aunt怎么读.对于的情况分别求解.
精确解为.对得到的结果与精确解的差异进行解释.
数值实验2  Lagrange插值
莫言txt下载数值实验内容:对一组数据做Lagrange插值,根据插值多项式估计函数值.
调用格式:yi=Lagran_(x,y,xi)
x,y: 数组形式的数据表
xi: 待计算函数值的横坐标数组
yi: 用Lagrange插值多项式算出的y值数组
Function fi=Lagran_(x,f,xi)
fi=zeros(size(xi))
npl=length(f)
for i=1:npl
  z=ones(size(xi))
roger huerta  for j=1:npl
    if I~=j,z=z.*(xi-x(j))/(x(i)-x(j));end
  end
  fi=fi+z*f(i)
end
return
实验题目:
1、已知函数的如下函数值:
构造Lagrange插值多项式,并估计的近似值.
数值实验4.2 最小二乘法
实验题目 
1、已知如下数据:
uptting
colleagues
(1) 利用最小二乘法拟合曲线
程序清单
x=[0.0,0.2,0.4,0.6,0.8,1.0,1.2]
y=[0.9,1.9,2.8,3.3,4.0,5.7,6.5]
a=polyfit(x,y,1)
计算结果
a =
wuha
利用最小二乘法求n次多项式拟合曲线
时,Matlab程序只有三行:前两行以数组形式分别输入;第三行输入a=polyfit(x,y,n).
Matlab以数组形式依次输出结果:
(2) 请读者根据本题中提供的数据,求二次多项式拟合曲线,并与前面的结果相比较.
2、求形如的经验公式,使它能和下列数据相拟合
1
2
3
4
5
6
7
8
数值实验3数值积分
一、方法与程序
Gauss-Lengder求积公式 利用个非等长点的采样求积分:
的逼近.使用变量替换:
横坐标权必须从一个表中获得
Gauss-Lengder求积算法(MATLAB程序)
Function quad =G-L(f,a,b,A,w)
%Input  - f is the integrand input as string ‘f’
%      - a and b are upper and lower limits of integration
%      - A is 1N vector of abscissas from the table
%      - w is 1N vector of wights from the table
%Output  -quad is the quadrature value
zest
N = length(A);
T=zeros(1,N);
T=((a+b)/2)+((b-a)/2)*A
quad=((a+b)/2)*sum(w.*feval(f,T));
复化Simpson求积公式  利用个等步长采样点:
的逼近积分.注意:
复化Simpson求积算法(MATLAB程序
Function s =simpson(f,a,b,N)
%Input  - f is the integrand input as a string ‘f’
%      - a and b are upper and lower limits of integration
%      - N is the number of subintervals
%Output  -s is the simpson rule sum
h= (b-a)/(2*N);
s1=0;
s2=0;
For k=1:N

本文发布于:2023-05-27 13:03:50,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/124530.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:数组   插值   实验   数值   数据   求积
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图