当前位置: 首页 > news >正文

电磁场有限元方法EX2.2-里兹法求解泊松方程控制的边值问题

电磁场有限元方法EX2.2-里兹法求解泊松方程控制的边值问题

简单学习一下有限元法的基础理论,书本为电磁场有限元经典教材:
THE FINITE ELEMENT METHOD IN ELECTROMAGNETICS, JIAN-MING JIN

目录

    • 电磁场有限元方法EX2.2-里兹法求解泊松方程控制的边值问题
      • 1、问题定义
        • 1.1、英文描述
        • 1.2、中文描述
      • 2、解题
        • 2.1、解题思路
        • 2.2、Matlab代码实现
          • 2.2.1 定义试探函数和变分问题
          • 2.2.2 变分F对c1、c2变量求偏导
          • 2.2.3 F对c1、c2变量偏导为0,建立方程并求解
          • 2.2.4 对比理论解和数值解,并绘图
        • 2.3、结果对比
      • 3、全部代码
      • 4、变分公式的证明

1、问题定义

1.1、英文描述

在这里插入图片描述

1.2、中文描述

给定由波动方程定义的边值问题:

d 2 ϕ d x 2 + 2 ϕ = 0 ( 0 < x < 1 ) \frac{\mathrm{d}^{2}\phi}{\mathrm{d}x^{2}} + 2\phi = 0 \quad (0 < x < 1) dx2d2ϕ+2ϕ=0(0<x<1)

边界条件:

ϕ ∣ x = 0 = 0 和 ϕ ∣ x = 1 = 1 \left.\phi\right|_{x = 0} = 0 \quad \text{和} \quad \left.\phi\right|_{x = 1} = 1 ϕx=0=0ϕx=1=1

证明该问题的泛函 F F F为:

F ( ϕ ~ ) = 1 2 ∫ 0 1 [ ( d ϕ ~ d x ) 2 − 2 ϕ ~ 2 ] d x F(\tilde{\phi}) = \frac{1}{2} \int_{0}^{1} \left[ \left( \frac{\mathrm{d} \tilde{\phi}}{\mathrm{d} x} \right)^{2} - 2 \tilde{\phi}^{2} \right] \mathrm{d}x F(ϕ~)=2101 (dxdϕ~)22ϕ~2 dx

应用里茨方法,使用试探函数:

ϕ ~ ( x ) = x + ∑ n = 1 N c n sin ⁡ ( n π x ) ( 取  N = 2 ) \tilde{\phi}(x) = x + \sum_{n=1}^{N} c_{n} \sin(n\pi x) \quad (\text{取 } N = 2) ϕ~(x)=x+n=1Ncnsin(x)( N=2)

求近似解,并将结果与精确解:

ϕ = sin ⁡ ( 2 x ) sin ⁡ 2 \phi = \frac{\sin(\sqrt{2}\, x)}{\sin\sqrt{2}} ϕ=sin2 sin(2 x)

进行比较。

2、解题

2.1、解题思路

这题比较简单,使用经典里兹方法,将试探函数 ϕ ~ ( x ) \tilde{\phi}(x) ϕ~(x)带入泛函 F F F中,然后对泛函 F F F求c1和c2的偏导即可( F F F对c1,c2的偏导为0,以此求得极小值)。变分公式的证明见最后

下面使用matlab实现代码思路

2.2、Matlab代码实现
2.2.1 定义试探函数和变分问题

定义试探函数和变分问题,并将试探函数带入变分:

%% Solve
syms x c1 c2
% define the trail function and variational functional
phi = x+c1*sin(pi*x) +c2*sin(2*pi*x);
F=0.5*int((diff(phi, x))^2-2*(phi^2),x,0,1);
disp('F=');
pretty(simplify(F))
2.2.2 变分F对c1、c2变量求偏导
% Find the extreme value of the functional. calculate the partial derivative of c
diff_c1 = diff(F, c1);  % ∂F/∂c1
diff_c2 = diff(F, c2);  % ∂F/∂c2
2.2.3 F对c1、c2变量偏导为0,建立方程并求解
% Solve the system of equations for variables [c1, c2]
equations = [diff_c1 == 0, diff_c2 == 0];
solutions = solve(equations, [c1, c2]);
disp('Solution:');
% Extract all solutions for c1 and c2
c1_val = double(solutions.c1);
c2_val = double(solutions.c2);
% Display results (both symbolic and numeric forms)
disp(['c1 = ', num2str(c1_val)]);
disp(['c2 = ', num2str(c2_val)]);
2.2.4 对比理论解和数值解,并绘图
phi_curve=subs(phi, {c1, c2}, {c1_val, c2_val});
phi_curve_exact=sin(sqrt(2)*x)/sin(sqrt(2));%% Draw figure
figure(1)
fplot(phi_curve, [0, 1], ...'Color', [0, 0.4470, 0.7410], ... % MATLAB经典蓝'LineStyle', '--', ...             % 虚线'LineWidth', 2.5, ...'Marker', 'o', ...                 % 圆形标记'MarkerSize', 7, ...'MarkerFaceColor', 'auto', ...     % 自动填充'MarkerEdgeColor', 'k', ...        % 黑色边框'DisplayName', sprintf('Numerical: $\\phi(x) = x + %.2f\\sin(\\pi x) + %.2f\\sin(2\\pi x)$', c1_val, c2_val));hold on
fplot(phi_curve_exact, [0, 1], ...'Color', [0.8500, 0.3250, 0.0980], ... % MATLAB经典红'LineStyle', '-', ...                   % 实线'LineWidth', 2.5, ...'Marker', 's', ...                      % 正方形标记'MarkerSize', 8, ...'MarkerFaceColor', 'auto', ...           % 自动填充'DisplayName', 'Exact: $\frac{\sin(\sqrt{2} x)}{\sin(\sqrt{2})}$');xlabel('Position (x)', 'FontSize', 14);
ylabel('Function Value \phi(x)', 'FontSize', 14);
title('Comparison of Numerical and Exact Solutions', 'FontSize', 16);
xlim([0, 1]);legend('Interpreter', 'latex', 'Location', 'best', 'FontSize', 12);set(gca, 'FontSize', 12, 'GridAlpha', 0.3, 'Box', 'on');
grid minor;
2.3、结果对比

可以看到数值解和解析解是几乎一致的:
在这里插入图片描述

3、全部代码

% Exercise 2.2 THE FINITE ELEMENT METHOD IN ELECTROMAGNETICS JIN JIAN MINGclc
clear
%% Solve
syms x c1 c2
% define the trail function and variational functional
phi = x+c1*sin(pi*x) +c2*sin(2*pi*x);
F=0.5*int((diff(phi, x))^2-2*(phi^2),x,0,1);
disp('F=');
pretty(simplify(F))% Find the extreme value of the functional. calculate the partial derivative of c
diff_c1 = diff(F, c1);  % ∂F/∂c1
diff_c2 = diff(F, c2);  % ∂F/∂c2% Solve the system of equations for variables [c1, c2]
equations = [diff_c1 == 0, diff_c2 == 0];
solutions = solve(equations, [c1, c2]);
disp('Solution:');
% Extract all solutions for c1 and c2
c1_val = double(solutions.c1);
c2_val = double(solutions.c2);
% Display results (both symbolic and numeric forms)
disp(['c1 = ', num2str(c1_val)]);
disp(['c2 = ', num2str(c2_val)]);phi_curve=subs(phi, {c1, c2}, {c1_val, c2_val});
phi_curve_exact=sin(sqrt(2)*x)/sin(sqrt(2));%% Draw figure
figure(1)
fplot(phi_curve, [0, 1], ...'Color', [0, 0.4470, 0.7410], ... % MATLAB经典蓝'LineStyle', '--', ...             % 虚线'LineWidth', 2.5, ...'Marker', 'o', ...                 % 圆形标记'MarkerSize', 7, ...'MarkerFaceColor', 'auto', ...     % 自动填充'MarkerEdgeColor', 'k', ...        % 黑色边框'DisplayName', sprintf('Numerical: $\\phi(x) = x + %.2f\\sin(\\pi x) + %.2f\\sin(2\\pi x)$', c1_val, c2_val));hold on
fplot(phi_curve_exact, [0, 1], ...'Color', [0.8500, 0.3250, 0.0980], ... % MATLAB经典红'LineStyle', '-', ...                   % 实线'LineWidth', 2.5, ...'Marker', 's', ...                      % 正方形标记'MarkerSize', 8, ...'MarkerFaceColor', 'auto', ...           % 自动填充'DisplayName', 'Exact: $\frac{\sin(\sqrt{2} x)}{\sin(\sqrt{2})}$');xlabel('Position (x)', 'FontSize', 14);
ylabel('Function Value \phi(x)', 'FontSize', 14);
title('Comparison of Numerical and Exact Solutions', 'FontSize', 16);
xlim([0, 1]);legend('Interpreter', 'latex', 'Location', 'best', 'FontSize', 12);set(gca, 'FontSize', 12, 'GridAlpha', 0.3, 'Box', 'on');
grid minor;

4、变分公式的证明

在这里插入图片描述

http://www.dtcms.com/a/265199.html

相关文章:

  • 二刷 苍穹外卖day11
  • 讲解视频:分布滞后非线性模型DLNM​​专题:从基础到进阶学习路径
  • 记录一个QT中pro文件换行需要注意的问题
  • 第29篇:Linux审计系统深度解析:基于OpenEuler 24.03的实践指南
  • 【中文核心期刊推荐】《电子测量技术》
  • RabbitMQ使用topic Exchange实现微服务分组订阅
  • 基于SEP3203微处理器的嵌入式最小硬件系统设计
  • VBA初学习记录
  • OneCode表单架构设计:注解驱动与组件化的完美结合
  • 腾讯云认证考试报名 - TDSQL数据库交付运维专家(TCCE PostgreSQL版)
  • windows的vscode无法通过ssh连接ubuntu的解决办法
  • 网站面临爬虫攻击waf能防护住吗
  • docker拉取redis并使用
  • 《导引系统原理》-西北工业大学-周军
  • CppCon 2018 学习:Fast Conversion From UTF-8 with C++, DFAs, and SSE Intrinsics
  • 部署 KVM 虚拟化平台
  • 关于网络协议
  • 第四篇:面试官:SpringBoot 场景化实战 10 问(第四弹·附图解)
  • C语言笔记(鹏哥)上课板书+课件汇总 (编译和链接+linux讲解)
  • 【实战】CRMEB Pro 企业版安装教程(附 Nginx 反向代理配置 + 常见问题解决)
  • 深入理解C++11原子操作:从内存模型到无锁编程
  • Docker Dify安装 完整版本
  • Pytorch中torch.where()函数详解和实战示例
  • AIGC自我介绍笔记
  • Redis基础(1):NoSQL认识
  • sqlmap学习笔记ing(3.[MoeCTF 2022]Sqlmap_boy,cookie的作用)
  • UniApp完美对接RuoYi框架开发企业级应用
  • 基于 ethers.js 的区块链事件处理与钱包管理
  • UI前端大数据可视化实战技巧:动态数据加载与刷新策略
  • 【AI智能体】Coze 搭建个人旅游规划助手实战详解