Hi there, I was running the spiral.m script in my computer and getting the following error.
Not enough input arguments.
"Error in spiral (line 19)
h = 2*L/n;"
My code:
function [T,W] = Spiral(n,L,Tend,nplots,D,e)
% function [T,Y] = Spiral(n,L,Tend,nplots,D,e)
% nominal usage: [T,Y] = Spiral(128,8,50,20,0.1,0.1)
% method of lines finite difference approximation for
% Fitzhugh-Nagumo equations, periodic domain
% Input: n is number of subintervals across domain
% L is half-width of domain, -L<x,y<L
% Tend is the end time, 0<t<Tend
% nplots is the number during the time interval (nplots+1 if t=0
% included)
% D is diffusivity (try 1,0.5,0.25,0.1)
% Output: T is time levels for answer (nplots+1)
% Y is the answer at T, needs to be reshaped to n+1 by n+1 grid
b = 0.67;
%e = 1;
%D = 0.1;
h = 2*L/n;
x = -L + h*(0:n)'; % includes boundary
y = x;
[X,Y] = ndgrid(x,y);
Xi = X(1:n,1:n); Yi = Y(1:n,1:n); % interior points + one boundary
% set up ICS
u = 5*ones(n,1)*([1:n]-0.4*n)/n;
v = 5*(([1:n]-0.4*n)')*ones(1,n)/n;
y0(1:n^2,1) = reshape(u,n^2,1);
y0(n^2+1:2*n^2,1) = reshape(v,n^2,1);
w=y0;
% Set up the one-dimensional 2nd-derivative matrices.
Dxx = toeplitz( [-2 1 zeros(1,n-2)]/h^2 );
Dxx(1,n) = 1; Dxx(n,1) = 1; % periodic box case
Dxx = sparse(Dxx);
Dyy = Dxx;
% Form discrete Laplacian.
I = speye(n);
A = sparse(kron(Dxx,I) + kron(I,Dyy));
MyTols = odeset('RelTol',1e-4,'AbsTol',1e-5);
[T,W] = ode45(@(t,u) rhs(t,u,A,D,b,e,n),[0:Tend/20:Tend],y0,MyTols);
for ii = 1:length(T)
u = reshape(W(ii,1:n^2),n,n);
max(max(u))
v = reshape(W(ii,n^2+1:2*n^2),n,n);
figure
% colormap(hot); axis image off;
%surface(Xi,Yi,u)
colormap(hsv), pcolor(u)
pause(1)
end
function dydt = rhs(t,z,A,D,b,e,n)
% right-hand side.
u1 = z(1:n^2,1);
u2 = z(n^2+1:2*n^2,1);
dydt = z;
dydt(1:n^2,1) = D*(A*u1)+(u1-u1.^3/3-u2)/e;
dydt(n^2+1:2*n^2,1) = e*(u1-u2/2+b);
end
end
What should I do now?
Best Regards
Zillur

댓글 수: 1

Tamir Suliman
Tamir Suliman 2016년 12월 4일
please upload the code or fix the formatting I dont know which is commented out and which is not

댓글을 달려면 로그인하십시오.

 채택된 답변

Image Analyst
Image Analyst 2016년 12월 4일

0 개 추천

Why don't you step through it with the debugger? We can't run your code because you didn't supply us with values for the input arguments n,L,Tend,nplots,D,& e. What did you pass in for those?
Say, you didn't just try to run the program by typing F5 or clicking the green run triangle, without passing in values, did you? Of course, you can't do that. What could it possibly use for n,L,Tend,nplots,D, & e? It can't just guess. You have to tell it.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Error Functions에 대해 자세히 알아보기

질문:

2016년 12월 4일

댓글:

2016년 12월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by