In: Computer Science
Matlab: When I plot "figure (3)", I would like it to produce three lines/curves instead of data points. Currently, the code will only produce a plot when I use characters and symbols. Please help...
%-------------------------------------------------------------------------------------------------------------%
clear all
close all
clc
xmax=1;
ne=100;
nx=ne+1;
dx=xmax/ne;
dxdx=dx+dx;
dx2=dx*dx;
dt=0.02;
%-------------------------------------------------------------------------------------------------------------%
for i=1:nx
u(i)=0;
bvec(i)=0;
end
u=u';
bvec=bvec';
amat(1,1)=1;
for i=2:nx-1
amat(i,i)=(2/dx2)+(1/dt);
amat(i,i-1)=-(1/dx2);
amat(i,i+1)=-(1/dx2);
end
amat(nx,nx)=1;
av=inv(amat);
for it=1:100
zt(it)=(it-1)*dt;
bvec(1)=-exp(-(zt(it)-0.5)^2/0.03);
for j=2:nx-1
bvect(j)=(u(j)/dt)+(1/2*u(j));
end
bvec(nx)=zt(it)*(sin(4*zt(it)))^4;
u=av*bvec;
for j=1:nx
out(it,j)=u(j);
end
end
%-------------------------------------------------------------------------------------------------------------%
figure(1)
mesh(out)
xlabel('X')
ylabel('Time')
zlabel('Temperature')
title('Temperature as a Function of Time and Space')
%-------------------------------------------------------------------------------------------------------------%
figure(2)
pcolor(out)
xlabel('X')
ylabel('Time')
title('Temperature as a Function of Time and Space')
%-------------------------------------------------------------------------------------------------------------%
figure(3)
for k=1:ne
plot(zt(k),out(k,1),'r*')
hold on
plot(zt(k),out(k,31),'b*')
hold on
plot(zt(k),out(k,61),'g*')
hold on
end
title('Time History of Temperature at Different Locations')
xlabel('Time')
ylabel('Temperature')
legend('x=0.0','x=0.3','x=0.6')
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
%-------------------------------------------------------------------------------------------------------------%
clear all
close all
clc
xmax=1;
ne=100;
nx=ne+1;
dx=xmax/ne;
dxdx=dx+dx;
dx2=dx*dx;
dt=0.02;
%-------------------------------------------------------------------------------------------------------------%
for i=1:nx
u(i)=0;
bvec(i)=0;
end
u=u';
bvec=bvec';
amat(1,1)=1;
for i=2:nx-1
amat(i,i)=(2/dx2)+(1/dt);
amat(i,i-1)=-(1/dx2);
amat(i,i+1)=-(1/dx2);
end
amat(nx,nx)=1;
av=inv(amat);
for it=1:100
zt(it)=(it-1)*dt;
bvec(1)=-exp(-(zt(it)-0.5)^2/0.03);
for j=2:nx-1
bvect(j)=(u(j)/dt)+(1/2*u(j));
end
bvec(nx)=zt(it)*(sin(4*zt(it)))^4;
u=av*bvec;
for j=1:nx
out(it,j)=u(j);
end
end
%-------------------------------------------------------------------------------------------------------------%
figure(1)
mesh(out)
xlabel('X')
ylabel('Time')
zlabel('Temperature')
title('Temperature as a Function of Time and Space')
%-------------------------------------------------------------------------------------------------------------%
figure(2)
pcolor(out)
xlabel('X')
ylabel('Time')
title('Temperature as a Function of Time and Space')
%-------------------------------------------------------------------------------------------------------------%
figure(3)
plot(zt(1:ne),out(1:ne,1),'-r');
hold on;
plot(zt(1:ne),out(1:ne,31),'-b');
hold on;
plot(zt(1:ne),out(1:ne,61),'-g');
title('Time History of Temperature at Different Locations')
xlabel('Time')
ylabel('Temperature')
legend('x=0.0','x=0.3','x=0.6')
Kindly revert for any queries
Thanks.