How to check a value in a loop at a certain instance?

1 回表示 (過去 30 日間)
Westin Messer
Westin Messer 2018 年 11 月 27 日
コメント済み: Cris LaPierre 2018 年 11 月 28 日
I want to know what the value of u and v are when t = 7. Does anyone know how I'd do that?
close all;
clear all;
a = 0;
b = 20;
nel = 200; % number of elements
h = (b-a)/nel; % step size
nv = nel+1;% number of vertices
x = a:h:b; % mesh
dt = 0.001; % time steps
tend = 20;
e=ones(nv, 1);
%Discretization of the Laplace operator
Delta=1/(h^2)*spdiags([e -2*e e], -1:1, nv, nv);
Delta(1,2) = 2/h^2;
Delta(end,end-1) = -2/h^2;
% parameters of the model
eps = 0.01;
alpha = 0.1; %0.22 - max
beta = 0.2; % determines the width of the pulse
gamma = 0.25 * beta; % determines the shape of the pulse
D =2;
% Max D = 8;
% Min D = 1.7;
% initial guess
u = 0.5 * (x < 3);
v = 0 * x;
counter = 1;
% explicit Euler scheme
g=dt:dt:tend;
for t=dt:dt:tend
u = u + dt * eps* (D*((Delta * u')')) + dt/eps * (u .* (1 -u ).*(u-alpha) - v);
v = v + dt * (gamma * u - beta * v);
end

回答 (1 件)

Cris LaPierre
Cris LaPierre 2018 年 11 月 28 日
Set a conditional breakpoint inside the loop set equal to when t==7
  2 件のコメント
Cris LaPierre
Cris LaPierre 2018 年 11 月 28 日
And since that link doesn't say how to do it, rt click on the line number you want to add the break to and select "Set Conditional Breakpoint..."
Cris LaPierre
Cris LaPierre 2018 年 11 月 28 日
And here's some info on how to debug in MATLAB

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by