matlab编程实践16、17

捕食者与猎物模型


人口增长


        在人口增长或衰减的最简单模型中,增长速度或衰减速度与人口本身的数目成正比。增加或减少人口规模会导致出生和死亡数量成比例地增加或减少。在数学上,可以由以下微分方程描述。

\dot{y}=ky

        可以得出:y(t)=\eta e^{kt},其中\eta =y(0)

        该简单模型在人口增长的初始阶段是正确的,因为初始阶段对人口没有限制。在现实情况下,人口数量增加时,其增长速度按照线性方式下降。这个微分方程模型有时称为logistic方程。

\dot{y}=k(1-y/\mu )y

y(t)=\frac{\mu \eta e^{kt}}{\eta e^{kt}+\mu-\eta }

        新参数μ为承载能力,当y(t)接近于μ,增长率接近于0,人口增长逐渐停止。

%% Exponential and Logistic Growth.采用指数增长和logistic增长
   close all
   figure
   k = 1
   eta = 1
   mu = 20
   t = 0:1/32:8;
   y = mu*eta*exp(k*t)./(eta*exp(k*t) + mu - eta);
   plot(t,[y; exp(t)])
   axis([0 8 0 22])
   title('Exponential and logistic growth')
   xlabel('t')
   ylabel('y')

或采用ode45来求常微分方程组的数值解:

%% ODE45 for the Logistic Model.
   figure
   k = 1
   eta = 1
   mu = 20
   ydot = @(t,y) k*(1-y/mu)*y
   ode45(ydot,[0 8],eta)

 在使用ode45求解时,@符号和@(t,y)可以定义出t和y的函数。变量t必须给出,即使某个微分方程像这里的方程那样不显含时间变量t。


捕食者与猎物模型


        捕食者和猎物模型为两个方程,这设计两个竞争物种y1(t)和y2(t)的变化情况。y1的增长率是y2的现象函数,反过来也是。

\dot{y_{1}}=(1-\frac{y_{2}}{\mu _{2}})y_{1}

\dot{y_{2}}=-(1-\frac{y_{1}}{\mu _{1}})y_{2}

        单物种logistic模型是有求解公式的,但对捕食者与猎物模型来说,不能得出包括指数函数、三角函数或其他基本函数的解析解,这时只能求出方程的数值解

ode45

function predprey(action)
% PREDPREY  Predator-prey gui.
% Drag the red dot to change equilibrium point.
% Drag the blue-green dot to change the initial conditions.

   % Default parameters.

   mu = [300 200]';     % Equilibrium.
   eta = [400 100]';    % Initial conditions.

   % Predator-prey ode

   function ydot = ppode(t,y);
      ydot = [(1-y(2)/mu(2))*y(1);
             -(1-y(1)/mu(1))*y(2)];
   end
  
   % Switchyard.

   if nargin == 0
      action = 'init';
   end
   switch action
      case 'init'
         initialize_graphics
      case 'down'
         locate_dot
         return
      case 'move'
         move_dot
      case 'up'
         free_dot
   end

   % Solve ode.

   [mu, eta] = get_parameters;
   opts = odeset('reltol',1.e-8,'events',@pitstop);
   [t,y,te] = ode45(@ppode,[0 100],eta,opts);

   % Update the plots.

   subplot1(y,action)
   subplot2(t,y,te,action)

   % ----------------------------------

   function [g,isterm,dir] = pitstop(t,y)
      % Event function called by the ode solver.
      % Terminate when y returns to the point where its angle
      % with mu is the same as the angle between eta and mu.
      sig = sign(eta(1)-mu(1)+realmin);
      theta1 = atan2(sig*(y(2)-mu(2)),sig*(y(1)-mu(1)));
      theta0 = atan2(sig*(eta(2)-mu(2)),sig*(eta(1)-mu(1)));
      g = theta1 - theta0;
      isterm = t > 1;
      dir = 1;
   end

   % ----------------------------------

   function initialize_graphics  %初始化图形
      % Set up two subplots, buttons, dots and empty plots.
      clf
      shg
      set(gcf,'units','normal','pos',[.25 .125 .50 .75])
      subplot(2,1,1)
      plot(0,0,'-','color','black');
      line(mu(1),mu(2),'marker','.','markersize',24,'color',[1 0 0]);
      line(eta(1),eta(2),'marker','.','markersize',24,'color',[0 1/2 1/2]);
      xlabel('prey')
      ylabel('predator')
      title('Drag either dot')
      subplot(2,1,2)
      plot(0,[0 0]);
      line([0 0],[0 0],'color','black');
      line([0 0],[0 0],'color','black');
      xlabel('time')
      legend('prey','predator','period','location','northwest')
      set(gcf,'windowbuttondownfcn','predprey(''down'')', ...
              'windowbuttonmotionfcn','predprey(''move'')', ...
              'windowbuttonupfcn','predprey(''up'')')
      set(gcf,'userdata',[])
   end

   % ----------------------------------

   function locate_dot
      % Find if the mouse is selecting one of the dots.
      point = get(gca,'currentpoint');
      h = get(gca,'children');
      y1 = get(h(1:2),'xdata');
      y2 = get(h(1:2),'ydata');
      d = abs([y1{:}]'-point(1,1)) + abs([y2{:}]'-point(1,2));
      k = min(find(d == min(d)));
      tol = .025*max(abs(axis));
      if d(k) < tol
         set(gcf,'userdata',h(k))
      else
         set(gcf,'userdata',[])
      end
   end

   % ----------------------------------

   function move_dot
      % Move the selected dot to a new position.
      point = abs(get(gca,'currentpoint'));
      hit = get(gcf,'userdata');
      if ~isempty(hit)
         set(hit,'xdata',point(1,1),'ydata',point(1,2))
      end
   end

   % ----------------------------------

   function free_dot
      % Deselect the dot.
      set(gcf,'userdata',[])
   end

   % ----------------------------------

   function [mu,eta] = get_parameters
      % Obtain mu and eta from the two dots.
      subplot(2,1,1);
      h = get(gca,'children');
      mu = [get(h(2),'xdata') get(h(2),'ydata')]';
      eta = [get(h(1),'xdata') get(h(1),'ydata')]';
   end

   % ----------------------------------

   function subplot1(y,action)
      % Redraw the phase plane plot and perhaps rescale.
      subplot(2,1,1)
      h = get(gca,'children');
      set(h(3),'xdata',y(:,1),'ydata',y(:,2));
      if ~isequal(action,'move')
         y1max = max(max(y(:,1)),mu(1));
         y2max = max(max(y(:,2)),mu(2));
         axis([0 1.5*y1max 0 1.5*y2max])
      end
   end

   % ----------------------------------

   function subplot2(t,y,te,action)
      % Redraw the time plots, period line, and perhaps rescale.
      subplot(2,1,2)
      if length(te)==0 || te(end) < 1.e-6
         pit = 2*pi;
      else
         pit = te(end);
      end
      h = get(gca,'children');
      ymax = max(max(y));
      t = [t; t+pit; t+2*pit];
      y = [y; y; y];
      set(h(4),'xdata',t,'ydata',y(:,1));
      set(h(3),'xdata',t,'ydata',y(:,2));
      set(h(2),'xdata',[pit pit],'ydata',[0 3*ymax]);
      set(h(1),'xdata',[2*pit 2*pit],'ydata',[0 3*ymax]);
      set(gca,'xtick',[0 pit 2*pit])
      if ~isequal(action,'move')
         axis([0 2.5*pit 0 1.5*ymax])
      end
      subplot(2,1,1)
   end
end


轨道


        轨道是多天体系统的动力学问题。


弹跳球模型


eps

在初始时刻小球上抛之后,地球的引力是的速度每步都按照固定的比率g减少。

%% Core of bouncer, simple gravity. no gravity

   % Initialize

   z0 = eps;
   g = 9.8;
   c = 0.75;
   delta = 0.005;
   v0 = 21;
   y = [];

   % Bounce 

   while v0 >= 1
      v = v0;
      z = z0;
      while z >= 0
         v = v - delta*g;
         z = z + delta*v;
         y = [y  z];
      end
      v0 = c*v0;
   end

   % Simplified graphics

   close all
   figure
   plot(y)


布朗运动


        随机游走(random walk)的简单布朗运动

%% Snapshot of two dimensional Brownian motion.

   figure
   m = 100;
   x = cumsum(randn(m,1));
   y = cumsum(randn(m,1));
   plot(x,y,'.-')
   s = 2*sqrt(m);
   axis([-s s -s s]);

%% Snapshot of three dimensional Brownian motion, brownian3

   n = 50; %粒子个数
   delta = 0.125;
   P = zeros(n,3);
   
   for t = 0:10000
      % Normally distributed random velocities.生成正态分布的随机速度
      V = randn(n,3);
      % Update positions. 更新位置
      P = P + delta*V;
   end

   figure
   plot3(P(:,1),P(:,2),P(:,3),'.')
   box on


 n天体问题


(1)前向法(显式欧拉法)

(2)后向法(隐式欧拉法)

(3)耦对法(前两种方法的折中)

function orbits(n,gui)
% ORBITS  n-body gravitational attraction for n = 2, 3 or 9.
%   ORBITS(2), two bodies, classical elliptic orbits.
%   ORBITS(3), three bodies, artificial planar orbits.
%   ORBITS(9), nine bodies, the solar system with one sun and 8 planets.
%
%   ORBITS(n,false) turns off the uicontrols and generates a static plot.
%   ORBITS(n,false) 关闭 uicontrols 并生成静态图。
%   ORBITS with no arguments is the same as ORBITS(9,true).

   % n = number of bodies.
   % P = n-by-3 array of position coordinates.
   % V = n-by-3 array of velocities
   % M = n-by-1 array of masses
   % H = graphics and user interface handles

   if (nargin < 2)
      gui = true;
   end
   if (nargin < 1);
      n = 9;
   end

   [P,V,M] = initialize_orbits(n);
   H = initialize_graphics(P,gui);

   steps = 20;     % Number of steps between plots
   t = 0;          % time

   while get(H.stop,'value') == 0

      % Obtain step size from slider.
      delta = get(H.speed,'value')/(20*steps);
      
      for k = 1:steps

         % Compute current gravitational forces.
         G = zeros(size(P));
         for i = 1:n
            for j = [1:i-1 i+1:n];
               r = P(j,:) - P(i,:);
               G(i,:) = G(i,:) + M(j)*r/norm(r)^3;
            end
         end
 
         % Update velocities using current gravitational forces.
         V = V + delta*G;
        
         % Update positions using updated velocities.
         P = P + delta*V;

      end

      t = t + steps*delta;
      H = update_plot(P,H,t,gui);
   end

   finalize_graphics(H,gui)
end 

%% Inialize orbits ---------------------------------------------------

function [P,V,M] = initialize_orbits(n)

   switch n

%% Two bodies

   case 2

      % Initial position, velocity, and mass for two bodies.
      % Resulting orbits are ellipses.

      P = [-5  0  0
           10  0  0];
      V = [ 0  -1  0
            0   2  0];
      M = [200  100  0];

%% Three bodies

   case 3

      % Initial position, velocity, and mass for the artificial
      % planar three body problem discussed in the text.

      P = [ 0   0   0
           10   0   0
            0  10   0]; 
      V = [-1  -3   0
            0   6   0
            3  -3   0];
      M = [300  200  100]';

%% Nine bodies

   case 9

      % The solar system.
      % Obtain data from Jet Propulsion Laboratory HORIZONS.
      % http://ssd.jpl.nasa.gov/horizons.cgi  
      % Ephemeris Type: VECTORS
      % Coordinate Orgin: Sun (body center)
      % Time Span: 2008-7-24 to 2008-7-25
      
      sol.p = [0 0 0];
      sol.v = [0 0 0];
      sol.m = 1.9891e+30;
   
      ear.p = [ 5.28609710e-1 -8.67456608e-1  1.28811732e-5];
      ear.v = [ 1.44124476e-2  8.88154404e-3 -6.00575229e-7];
      ear.m = 5.9736e+24;
      
      mar.p = [-1.62489742e+0 -2.24489575e-1  3.52032835e-2];
      mar.v = [ 2.43693131e-3 -1.26669231e-2 -3.25240784e-4];
      mar.m = 6.4185e+23;
      
      mer.p = [-1.02050180e-2  3.07938393e-1  2.60947941e-2];
      mer.v = [-3.37623365e-2  9.23226497e-5  3.10568978e-3];
      mer.m = 3.302e+23;
      
      ven.p = [-6.29244070e-1  3.44860019e-1  4.10363705e-2];
      ven.v = [-9.80593982e-3 -1.78349270e-2  3.21808697e-4];
      ven.m = 4.8685e+24;
      
      jup.p = [ 1.64800250e+0 -4.90287752e+0 -1.65248109e-2];
      jup.v = [ 7.06576969e-3  2.76492888e-3 -1.69566833e-4];
      jup.m = 1.8986e+27;
      
      sat.p = [-8.77327303e+0  3.13579422e+0  2.94573194e-1];
      sat.v = [-2.17081741e-3 -5.26328586e-3  1.77789483e-4];
      sat.m = 5.6846e+26;
      
      ura.p = [ 1.97907257e+1 -3.48999512e+0 -2.69289277e-1];
      ura.v = [ 6.59740515e-4  3.69157117e-3  5.11221503e-6];
      ura.m = 8.6832e+25;
      
      nep.p = [ 2.38591173e+1 -1.82478542e+1 -1.74095745e-1];
      nep.v = [ 1.89195404e-3  2.51313400e-3 -9.54022068e-5];
      nep.m = 1.0243e+26;
   
      P = [sol.p; ear.p; mar.p; mer.p; ven.p; jup.p; sat.p; ura.p; nep.p];
      V = [sol.v; ear.v; mar.v; mer.v; ven.v; jup.v; sat.v; ura.v; nep.v];
      M = [sol.m; ear.m; mar.m; mer.m; ven.m; jup.m; sat.m; ura.m; nep.m];
   
      % Scale mass by solar mass.
      M = M/sol.m;
   
      % Scale velocity to radians per year.
      V = V*365.25/(2*pi);
   
      % Adjust sun's initial velocity so that system total momentum is zero.
      V(1,:) = -sum(diag(M)*V);

   otherwise

      error('No initial data for %d bodies',n)

   end  % switch

end

%% Initialize graphics --------------------------------------

function  H = initialize_graphics(P,gui)
% Initialize graphics and user interface controls
% H = initialize_graphics(P,gui)
% H = handles, P = positions, gui = true or false for gui or static plot.

   dotsize = [36 18 16 12 18 30 24 20 18]';
   color = [4 3 0     % gold
            0 0 3     % blue
            4 0 0     % red
            2 0 2     % magenta
            1 1 1     % gray
            3 0 0     % dark red
            4 2 0     % orange
            0 3 3     % cyan
            0 2 0]/4; % dark green

   clf reset
   n = size(P,1);
   s = max(sqrt(diag(P*P')));
   if n <= 3, s = 2*s; end
   axis([-s s -s s -s/4 s/4])
   axis square
   if n <= 3, view(2), end
   box on
   for i = 1:n
      H.bodies(i) = line(P(i,1),P(i,2),P(i,3),'color',color(i,:), ...
         'marker','.','markersize',dotsize(i),'userdata',dotsize(i));
   end

   H.clock = title('0 years','fontweight','normal');
   H.stop = uicontrol('string','stop','style','toggle', ...
     'units','normal','position',[.90 .02 .08 .04]);
   if n < 9
      maxsp = 0.5;
   else
      maxsp = 10;
   end
   if gui
      H.speed = uicontrol('style','slider','min',0,'value',maxsp/4, ...
         'max',maxsp,'units','normal','position',[.02 .02 .30 .04], ...
         'sliderstep',[1/20 1/20]);
      uicontrol('string','trace','style','toggle','units','normal', ...
         'position',[.34 .02 .06 .04],'callback','tracer');
      uicontrol('string','in','style','pushbutton','units','normal', ...
         'position',[.42 .02 .06 .04],'callback','zoomer(1/sqrt(2))')
      uicontrol('string','out','style','pushbutton','units','normal', ...
         'position',[.50 .02 .06 .04],'callback','zoomer(sqrt(2))')
      uicontrol('string','x','style','pushbutton','units','normal', ...
         'position',[.58 .02 .06 .04],'callback','view(0,0)')
      uicontrol('string','y','style','pushbutton','units','normal', ...
         'position',[.66 .02 .06 .04],'callback','view(90,0)')
      uicontrol('string','z','style','pushbutton','units','normal', ...
         'position',[.74 .02 .06 .04],'callback','view(0,90)')
      uicontrol('string','3d','style','pushbutton','units','normal', ...
         'position',[.82 .02 .06 .04],'callback','view(-37.5,30)')
   else
      H.traj = P;
      H.speed = uicontrol('value',maxsp,'vis','off');
   end
   set(gcf,'userdata',H)
   drawnow
end

%% Tracer ----------------------------------------------------------

function tracer
% Callback for trace button
   H = get(gcf,'userdata');
   bodies = flipud(H.bodies);
   trace = get(gcbo,'value');
   n = length(bodies);
   for i = 1:n
      if trace
         ms = 6;
         if n == 9 && i == 1, ms = 24; end
         set(bodies(i),'markersize',ms,'erasemode','none')
      else
         ms = get(bodies(i),'userdata');
         set(bodies(i),'markersize',ms,'erasemode','normal')
      end
   end
   if trace
      set(H.clock,'erasemode','xor')
   else
      set(H.clock,'erasemode','normal')
   end
end

%% Zoomer  ---------------------------------------------------

function zoomer(zoom)
% Callback for in and out buttons
   H = get(gcf,'userdata');
   [az,el] = view;
   view(3);
   axis(zoom*axis);
   view(az,el);
   set(H.speed,'max',zoom*get(H.speed,'max'), ...
      'value',zoom*get(H.speed,'value'));
end

%% Update plot ------------------------------------------------

function H = update_plot(P,H,t,gui)
   set(H.clock,'string',sprintf('%10.2f years',t/(2*pi)))
   for i = 1:size(P,1)
      set(H.bodies(i),'xdata',P(i,1),'ydata',P(i,2),'zdata',P(i,3))
   end
   if ~gui
      H.traj(:,:,end+1) = P;
      n = size(H.traj,1);
      switch n
         case 2, set(H.stop,'value',t > 11)
         case 3, set(H.stop,'value',t > 22.5)
         case 9, set(H.stop,'value',t > 200)
      end
   end
   drawnow
end

%% Finalize graphics  -------------------------------------------

function finalize_graphics(H,gui)
   delete(findobj('type','uicontrol'))
   uicontrol('string','close','style','pushbutton', ...
     'units','normal','position',[.90 .02 .08 .04],'callback','close');
   if ~gui
      n = size(H.traj,1);
      for i = 1:n
         line(squeeze(H.traj(i,1,:)),squeeze(H.traj(i,2,:)), ...
            squeeze(H.traj(i,3,:)),'color',get(H.bodies(i),'color'), ...
            'linewidth',2)
      end
   end
end
%% Run all three orbits, with 2, 3, and 9 bodies, and no gui.

   figure
   orbits(2,false)

   figure
   orbits(3,false)

   figure
   orbits(9,false)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/54623.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

2023-08-01 LeetCode每日一题(英雄的力量)

2023-08-01每日一题 一、题目编号 2681. 英雄的力量二、题目链接 点击跳转到题目位置 三、题目描述 给你一个下标从 0 开始的整数数组 nums &#xff0c;它表示英雄的能力值。如果我们选出一部分英雄&#xff0c;这组英雄的 力量 定义为&#xff1a; i0 &#xff0c;i1 &…

Redis - 三大缓存问题(穿透、击穿、雪崩)

缓存穿透 概念&#xff1a; 查询一个数据库中也不存在的数据&#xff0c;数据库查询不到数据也就不会写入缓存&#xff0c;就会导致一直查询数据库 解决方法&#xff1a; 1. 缓存空数据 如果数据库也查询不到&#xff0c;就把空结果进行缓存 缺点是 - 消耗内存 2. 使用布…

ModuleNotFoundError: No module named ‘_sqlite3‘

前言 遇到报错信息如下&#xff1a; ModuleNotFoundError: No module named _sqlite3解决方式 参考解决方式&#xff1a; https://blog.csdn.net/jaket5219999/article/details/53512071 find / -name _sqlite*.socp /usr/lib64/python3.6/lib-dynload/_sqlite3.cpython-36…

Go语言性能优化建议与pprof性能调优详解——结合博客项目实战

文章目录 性能优化建议Benchmark的使用slice优化预分配内存大内存未释放 map优化字符串处理优化结构体优化atomic包小结 pprof性能调优采集性能数据服务型应用go tool pprof命令项目调优分析修改main.go安装go-wrk命令行交互界面图形化火焰图 性能优化建议 简介&#xff1a; …

从0到1开发go-tcp框架【1-搭建server、封装连接与业务绑定、实现基础Router、抽取全局配置文件】

从0到1开发go-tcp框架【1-搭建server、封装连接与业务绑定、实现基础Router】 本期主要完成对Server的搭建、封装连接与业务绑定、实现基础Router&#xff08;处理业务的部分&#xff09;、抽取框架的全局配置文件 从配置文件中读取数据&#xff08;服务器监听端口、监听IP等&a…

记一次phpmyadmin巧妙利用

声明&#xff1a;文中涉及到的技术和工具&#xff0c;仅供学习使用&#xff0c;禁止从事任何非法活动&#xff0c;如因此造成的直接或间接损失&#xff0c;均由使用者自行承担责任。 点点关注不迷路&#xff0c;每周不定时持续分享各种干货。 原文链接&#xff1a;众亦信安&a…

Spring中最简单的过滤器和监听器

1. 过滤器概念引入 Filter也称之为过滤器&#xff0c;它是Servlet技术中最实用的技术&#xff0c;Web开发人员通过Filter技术&#xff0c;对web服务器管理的所有web资源&#xff1a;例如Jsp, Servlet, 静态图片文件或静态 html 文件等进行拦截&#xff0c;从而实现一些特殊的功…

在Windows 10和11中恢复已删除的照片

可以在Windows 10或11上恢复已删除的照片吗&#xff1f; 随着技术的发展&#xff0c;越来越多的用户习惯在电子设备上存储照片。如果这些照片被删除&#xff0c;可能会给用户带来重大损失。当照片丢失时&#xff0c;您可能会想是否可以恢复已删除的照片&#xff1f; …

LabVIEW 开发在不确定路况下自动速度辅助系统

LabVIEW 开发在不确定路况下自动速度辅助系统 智能驾驶辅助系统是汽车行业最先进的升级和尖端技术&#xff0c;智能交通系统依靠智能驾驶辅助系统在公共交通部门工作。该智能驾驶辅助系统技术包括自适应巡航控制&#xff0c;防抱死制动系统&#xff0c;安全气囊展开&#xff0…

腾讯云从业者认证考试考——云服务器

文章目录 云服务器的产品概览腾讯云服务器的优势腾讯云服务器选型腾讯云服务器计费方案 云服务器的产品概览 腾讯云服务器的产品&#xff1f; CVM云服务器&#xff08;Cloud Virtual Machine&#xff0c;CVM&#xff09;提供安全可靠的弹性计算服务。 可以在云端获取和启用 CV…

根据前序和中序遍历序列构造二叉树 (递归+迭代两种方法实现)

给定两个整数数组 preorder 和 inorder &#xff0c;其中 preorder 是二叉树的先序遍历&#xff0c; inorder 是同一棵树的中序遍历&#xff0c;请构造二叉树并返回其根节点。 输入: preorder [3,9,20,15,7], inorder [9,3,15,20,7] 输出: [3,9,20,null,null,15,7]源代码如下…

《吐血整理》进阶系列教程-拿捏Fiddler抓包教程(13)-Fiddler请求和响应断点调试

1.简介 Fiddler有个强大的功能&#xff0c;可以修改发送到服务器的数据包&#xff0c;但是修改前需要拦截&#xff0c;即设置断点。设置断点后&#xff0c;开始拦截接下来所有网页&#xff0c;直到取消断点。这个功能可以在数据包发送之前&#xff0c;修改请求参数&#xff1b…

逻辑回归变量系数可为负数吗?应该如何解释?

之前很多学员来问逻辑回归变量系数是否都应该为正数&#xff0c;如果出现负的变量系数该怎么办&#xff1f;是否需要重新建模&#xff1f;这些学员都是在网上搜索时&#xff0c;被错误信息误导。网上信息可以随意转载&#xff0c;且无人审核对错。我见过最多情况时很多文章正确…

第4章 案例研究:JavaScript图片库

案例 html部分 <h1 id"title">图片1</h1> <ul><li><!-- onclick绑定点击事件&#xff0c;this为触发dom&#xff0c;return false阻止默认行为 --><a onclick"show_img(this); return false" title"图片1" h…

命令模式-请求发送者与接收者解耦

去小餐馆吃饭的时候&#xff0c;顾客直接跟厨师说想要吃什么菜&#xff0c;然后厨师再开始炒菜。去大点的餐馆吃饭时&#xff0c;我们是跟服务员说想吃什么菜&#xff0c;然后服务员把这信息传到厨房&#xff0c;厨师根据这些订单信息炒菜。为什么大餐馆不省去这个步骤&#xf…

装饰器模式(Decorator)

装饰器模式是一种结构型设计模式&#xff0c;用来动态地给一个对象增加一些额外的职责。就增加对象功能来说&#xff0c;装饰器模式比生成子类实现更为灵活。装饰器模式的别名为包装器(Wrapper)&#xff0c;与适配器模式的别名相同&#xff0c;但它们适用于不同的场合。 Decor…

HTML笔记(1)

介绍 浏览器中内置了HTML的解析引擎&#xff0c;通过解析标记语言来展现网页&#xff1b;HTML标签都是预定义好的&#xff1b;Java工程师&#xff1a;后台代码的编写&#xff0c;和数据库打交道&#xff0c;把数据给网页前端的工程师&#xff1b;网页前端工程师&#xff1a;写H…

快速了解MyBatis---映射关系多对一

文章目录 映射关系多对一映射关系-官方文档映射关系多对1-基本介绍基本介绍注意细节 映射关系多对1-映射方式映射方式配置Mapper.xml 方式-应用实例注解实现多对1 映射-应用实例 映射关系多对一 映射关系-官方文档 文档地址: https://mybatis.org/mybatis-3/zh/sqlmap-xml.ht…

linux驱动定时器实现按键按下打印字符

#include <linux/init.h> #include <linux/module.h> #include <linux/of.h> #include <linux/of_irq.h> #include <linux/interrupt.h>struct device_node *dev; unsigned int irqno; //中断处理函数 irqreturn_t myirq_handler(int irq,void *…

51单片机--红外遥控

文章目录 红外遥控的介绍硬件电路NEC编码外部中断红外遥控实例代码 红外遥控的介绍 红外遥控是一种无线、非接触控制技术&#xff0c;通过使用红外线来传送控制信号。它具有抗干扰能力强、信息传输可靠、功耗低、成本低、易实现等显著优点&#xff0c;因此被广泛应用于各种电子…