How to execute once a different times loop in MATLAB?
Show older comments
Hello! Could anyone help me correct my loop operation. I want it to be executed for all the values of different times resulting in a matrix form values. However, it only shows me just the values of a first column instead of all columns.
t_i=0;
t_f=0.1;
a=0;
b=1;
dx=0.1;
dt=0.00001;
n=(t_f-t_i)/dt;
m=(b-a)/dx;
x=a:dx:b;
t=t_i:dt:t_f;
for i=1:m
TT(i,1) = exp((1-cos(pi*x(i)))/pi);
end
Phi1=zeros(m,1);
phi1=zeros(m,1);
u2=zeros(m,1);
Phi1=TT(:,end);
for i=1:m %for phi=-2*ln(Phi)
phi1(i,1)= log(Phi1(i,1));
end
for i=1:m %for u=(phi)x
if i==1
% phi(1,1)= phi(2,1); %forward difference BC
u2(i,1)= (phi1(i+1)-phi1(i))/(dx);
else if i==m
% phi(m +1,1)= phi(m,1); %backward difference BC
u2(i,1)= (phi1(i)-phi1(i-1))/(dx);
else
u2(i,1)= (phi1(i+1)-phi1(i-1))/(2*dx);
end
end
end
1 Comment
KSSV
on 21 Jun 2020
You have notused t any where in the code.....you have defined and it is unused.
Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!