Question

In: Computer Science

Matlab: When I plot "figure (3)", I would like it to produce three lines/curves instead of...

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')

Solutions

Expert Solution

`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.


Related Solutions

I would like to know how to plot two graphs in matlab and find where they...
I would like to know how to plot two graphs in matlab and find where they intercept.
I was asked to create a function called mydrawing in Matlab to draw or plot lines...
I was asked to create a function called mydrawing in Matlab to draw or plot lines onto a graph, using a so called pen. The pen will start at the origin and will move along the +ve horizontal axis. The pen is also supplied with a list of commands in a form of a string, to draw or plot the lines onto the graph. The string commands are: 1) 'F' : the pen moves forward by x = 1.0 2)...
Using MATLAB, plot the following curves for the crank angle range of 0-360: a. For an...
Using MATLAB, plot the following curves for the crank angle range of 0-360: a. For an engine that has R=3.5 and L=110 mm, plot the piston speed Sp at engine speeds of 500 RPM, 2000 RPM, and 5000 RPM on the same plot. b. For an engine that has L=110mm and running at an engine speed of 5000 RPM, plot the piston speed Sp at R = 3, 4, and 5 on the same plot. c. For each of the...
Use Matlab to do the following (please) : 1. Plot the following signals in one figure...
Use Matlab to do the following (please) : 1. Plot the following signals in one figure window using Matlab commands. Given x (n) = {5,2,1,3,1,4,2} plot x(3n) 2. Plot all transformations of a Gaussian signal in one figure window 3. Plot r(-3t-9).
When would you want to use value-of-service pricing instead of cost-of-service pricing? When would you like...
When would you want to use value-of-service pricing instead of cost-of-service pricing? When would you like use negotiated pricing?
Plot all four curves over 0 < t < 4 together using MATLAB. Post code in...
Plot all four curves over 0 < t < 4 together using MATLAB. Post code in the response. C1 : x=−5+2e−tcos20t y=−5+2e−tsin20t z=4t C2 : x=−5+2e−tcos20t y=5+2e−tsin20t z=4t C3 : x=5+2e−tcos20t y=−5+2e−tsin20t z=4t C4 : x=5+2e−tcos20t y=5+2e−tsin20t z=4t
I need to write a MATLAB code for this question, but I couldn't figure how to...
I need to write a MATLAB code for this question, but I couldn't figure how to do it. 7. Engineers often have to convert from one unit of measurement to another; this can be tricky sometimes. You need to think through the process carefully. For example, convert 5 acres to hectares, given that an acre is 4840 square yards, a yard is 36 inches, an inch is 2.54 cm, and a hectare is 10000 m2.
I am trying to plot a difficult function in MATLAB, however I need to understand the...
I am trying to plot a difficult function in MATLAB, however I need to understand the basics first. I am trying to plot n=0 for x=0:0.01:2pi n=n+1 y(n)=sin(x) end I beleive what this says, is that I want to plot sin(x) over a full period hence from o to 2pi, and I beleive the 0.01 is the incremenation along the x-axis. I am not sure what my n is doing Could smeone please graph this for me with the MATLAB...
I am in a statistics class. When I graduate, I would like to work in an...
I am in a statistics class. When I graduate, I would like to work in an area where I can help restructure businesses that are failing and make them successful. My professor has asked me where in my career that I think I will use the process of data collection. He has asked me to provide 2 examples. This is my first statistics class, so I don't really know of how to give him any examples. Can you please give...
e. Plot each of the following curves for the firm on a single diagram. i. Average...
e. Plot each of the following curves for the firm on a single diagram. i. Average variable costs ii. Average total costs iii. Marginal costs iv. Average fixed costs Illustrate and explain which of the curves will shift, and in which direction, due to a decrease in the cost of labour. Hint: use the definitions of the different costs to assist in determining which costs will change.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT