函数文件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:

 function g=Jacobian(x0,h,N)
% g(1,1)=1;
% g(1,2)=-h;
% g(2,1)=2*h*x0(1);
% g(2,2)=1;
g=zeros(N);
g(1,1)=4;
g(1,2)=-1;
g(2,1)=2*h^2*x0(1)-2;
g(2,2)=1;
for i=3:N
g(i,i-2)=1;
g(i,i-1)=2*h^2*x0(i-1)-2;
g(i,i)=1;
end

函数文件3:

 function x=newton_Iterative_method(f,u,h,N)
% u:上一节点的数值解或者初值
% x0 每次迭代的上一节点的数值
% x1 每次的迭代数值
% tol 允许误差
% f 右端函数
x0=u;
tol=1e-11;
x1=x0-Jacobian(x0,h,N)\F(f,x0,h,N);
while (norm(x1-x0,inf)>tol)
%数值解的2范数是否在误差范围内
x0=x1;
x1=x0-Jacobian(x0,h,N)\F(f,x0,h,N);
end
x=x1;%不动点

脚本文件:

 tic;
clear
clc
N=100;
h=1/N;
x=0:h:1;
y=inline('x.^2.*sin(x).^2+2*cos(x)-x.*sin(x)');
fun1=inline('x.*sin(x)');
Accurate=fun1(x);
f=y(x(2:N));
Numerical=zeros(N+1,1);
Numerical(2:end,1)=newton_Iterative_method(f,Numerical(2:end,1),h,N);
error=Numerical-Accurate';
subplot(1,3,1)
plot(x,Accurate);
xlabel('x');
ylabel('Accurate');
grid on
subplot(1,3,2)
plot(x,Numerical);
xlabel('x');
ylabel('Numerical');
grid on
subplot(1,3,3)
plot(x,error);
xlabel('x');
ylabel('error');
grid on
toc;

效果图:

Matlab:高阶常微分三种边界条件的特殊解法(中心差分法,高精度导数边界处理)的更多相关文章

  1. Matlab:高阶常微分三种边界条件的特殊解法(隐式Euler)

    函数文件1: function b=F(f,x0,u,h) b(1,1)=x0(1)-h*x0(2)-u(1); b(2,1)=x0(2)+h*x0(1)^2-u(2)-h*f; 函数文件2: fun ...

  2. Matlab:非线性高阶常微分方程的几种解法

    一.隐式Euler: 函数文件1: function b=F(t,x0,u,h) b(,)=x0()-h*x0()-u(); b(,)=x0()+*h*x0()/t+*h*(*exp(x0())+ex ...

  3. Matlab中数组元素引用——三种方法

    Matlab中数组元素引用——三种方法   1.Matlab中数组元素引用有三种方法 1 2 3 1.下标法(subscripts) 2.索引法(index) 3.布尔法(Boolean) 注意:在使 ...

  4. MATLAB 显示输出数据的三种方式

    MATLAB 显示输出数据的三种方式 ,转载 https://blog.csdn.net/qq_35318838/article/details/78780412 1.改变数据格式 当数据重复再命令行 ...

  5. 如何使用MATLAB对图片的RGB三种颜色进行提取

    参考: https://jingyan.baidu.com/article/456c463b41de5f0a5831448e.html matlab在图像处理方面,具有很强大的应用.下面将分享如何使用 ...

  6. matlab 高阶(三)—— 插值(fft、)

    1. FFT 插值 y = interpft(x,n) y = [0, .5, 1., 1.5, 2., 1.5, 1., .5, 0, -.5, -1, -1.5, -2., -1.5, -1., ...

  7. java高并发锁的三种实现

    提到锁大家会想到Synchronized同步关键字,使用它确实可以解决一切并发问题,但是对于体统吞吐量要求更高,在这里提供了几个小技巧.帮助大家减少锁粒度.提高系统的并发能力 一.乐观锁 试用场景:读 ...

  8. matlab 高阶(一) —— assignin与evalin

    1. assignin assignin(ws, 'var', val) 将 val 值赋值给 ws 空间中的 var 变量,注意这里的变量,必须是 array 类型,而不可以是包含下标索引,如果在指 ...

  9. python六十四课——高阶函数练习题(三)

    案例五:求两个列表元素的和,返回新列表lt1 = [1,2,3,4]lt2 = [5,6]效果:[6,8,10,12] lt1=[1,2,3,4] lt2=[5,6] print(list(map(l ...

随机推荐

  1. SpringBoot-外部运行jvm参数调优

    外部运行调优 java -server -Xms32m -Xmx32m  -jar springboot_v2.jar

  2. layer知识点总结

    1,本弹窗直接跳转父页面: <script>        window.parent.location.reload(); //刷新父页面        var index = pare ...

  3. (3.1)mysql备份与恢复之mysqldump

    目录: 1.单实例联系 1.1.备份单个数据库联系多种参数使用 [1]mysqldump命令备份演示 [2]查看备份文件 [3]用备份文件还原 1.2.mysqldump 各类参数释义 [1]--de ...

  4. docker+elasticsearch的安装

    查询镜像 [root@ elasticsearch]# docker search elasticsearch INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMA ...

  5. oracle数据库导出与导入

    一.查询导出库的字符集 3个 1.查询oracle server端的字符集 SQL>select userenv('language') from dual; USERENV('LANGUAGE ...

  6. 026-微软Ajax异步组件

    ASP.Net中内置的简化AJAX开发的控件UpdatePanel放入ScriptManager,将要实现AJAX效果的控件放到UpdatePanel中即可.UpdatePanel原理探秘,用Http ...

  7. Sitecore中Core,Master和Web数据库之间的区别

    Core数据库 正如名称所示,Core Database是Sitecore应用程序的主干,它可用于多种用途. 核心数据库包含所有Sitecore设置. 它包含桌面模式,内容编辑器,页面编辑器等的定义. ...

  8. css3 二维码 添加 扫描特效

    <section data-role="paragraph" class="_135editor" style="border: 0px non ...

  9. kubeflow 创建tensorflow过程

    online deployable ,install k8s 代码 Kubeflow有三个核心组件 TFJob Operator 和 Controller: 作为Kubernetes的扩展,来简化分布 ...

  10. 一些有趣的 js 包

    https://github.com/octalmage/robotjs Node.js桌面自动化.控制鼠标,键盘和屏幕. http://robotjs.io