For some, reason I am unable to run this matlab code, I was able to preallocate
ID: 2263354 • Letter: F
Question
For some, reason I am unable to run this matlab code, I was able to preallocate arrays as seen just before both for- loops but I didnt get any output upon running the script. Can you kindly help check the code:
%%MATLAB Code for the Forward in Time, Backward in Space (FTBS) Algorithm
N=100; %% No of grid points assumed
u=1; %assumed value of constant u in advection equation is 1
L=10;
dx=(L-0)/N; % grid space
dt=dx; %% defines the time step for stability of the FTBS scheme
a=0; b=L; %% sets initial time as zero. let 'a' & 'b' be the limits of'x'
x=a:dx:b; l=dt/dx; %%in current case but different if dt is changed
phi(1)=1;
j=1:N+1;
phin(j)=phi(x(j));
zeros(phin(j),phi(x(j)))
for j=1:N+1
phin(j)=phi(x(j));
end
phin(N+1)=1;phin(l)=1;
b2=phin(N+1); b1=phin(1); %%Boundary conditions
phin=[b1 phin(1:n) b2];
i=2:N+2;
phi(i)=phin(i)+u*l*phin(i-1)-u*l*phin(i);
zeros(phi(i))
for i=2:N+2
phi(i)=phin(i)-u*l*phin(i)+ u*l*phin(i-1);
end
plot(x,phi(2:N+2))
Explanation / Answer
phin(j)=phi(x(j));
zeros(phin(j),phi(x(j)))
for j=1:N+1
phin(j)=phi(x(j));
end
In the above script u gave phi(x(j)) , for example, ''arr'' is an array. In arr(i), 'i' is the index that must be integer. In our case x(j) is the index.x(j) is the fractional values not an integer. you have to modify it.