函数文件1: function b=F(f,x0,h,N) % b(1,1)=x0(1)-h*x0(2)-u(1); % b(2,1)=x0(2)+h*x0(1)^2-u(2)-h*f; b=zeros(N,1); b(1,1)=4*x0(1)-x0(2); b(2,1)=h^2*x0(1)^2-2*x0(1)+x0(2)-h^2*f(1) for i=3:N b(i,1)=x0(i-2)+h^2*x0(i-1)^2-2*x0(i-1)+x0(i)-h^2*f(i-1); end 函数文件2:
p47.(实习题-李荣华)用线性元求下列边值问题的数值解 tic; % this method is transform from Galerkin method %also call it as finit method %is used for solving two point BVP which is the first and second term. % %MATLAB 7.0 clear; clc; N=; h=/N; X=:h:; f=inline('(0.5*pi^2)*sin
函数文件: function [x,n,flag]=sor(A,b,eps,M,max1) %sor函数为用松弛迭代法求解线性方程组 %A为线性方程组的系数矩阵 %b为线性方程组的常数向量 %eps为精度要求 %M为超弛因子 %max1为最大迭代次数 %u为线性方程组的解 %n为迭代次数 %flag为指标变量,flag='OK!'表示迭代收敛达到指标要求 %flag='fail!'表示迭代失败 if nargin<5 max1=10000; end if nargin<4 M=1; end i