Can you help plot graph please
1 view (last 30 days)
Show older comments
With the code below, the values in the above table are reached. Can you draw the graph above accordingly?
Values ( L = 1.5 q = 0.0011 T = 11 dx = 0.25 R = 1 k = 100 dt = 0.0025 r = 16)
clc;
clear all;
L=input ('L:');
q=input('q:');
T=input('T:');
dx=input('dx:');
R= input('R:');
k=(T/q)^(1/2)
dt=R*dx/k
r= input('r');
c=L/dx+1;
u(1,1)=0;
u(1,c)=0;
u=zeros(r,c)
x=0:dx:L
%ilk satır hesaplamaları
for j=2:c-1
if (j<5)
u(1,j)=0.07*x(j);6,
else
u(1,j) = 0.21-0.14* x(j);
end
end
%ikinci satir hesaplamalari
for j = 2:c-1
u(2,j) = (u(1,j-1)+u(1,j+1)) / 2;
end
%diger satir hesaplamalari
for i = 3:r
for j = 2:c-1
u(i,j) = u(i-1,j-1)+u(i-1,j+1)-u(i-2,j);
end
end
%Matrisi yazdirma
for i = 1:r
for j = 1:c
fprintf('%.6f \t',u(i,j));
end
fprintf('\n');
end
0 Comments
Answers (1)
Amey Waghmare
on 25 Nov 2022
As per my understanding, you have created a table ‘u’ and and want to plot its rows against a vector ‘x’.
In order to plot a graph, you can use ‘plot’ function and specify the data as vector ‘x’ and ‘u(1,:)’. The plot function also allows you to specify Line Style, Color and Marker. Specifying ‘b--o’ in the plot function will set the plot with blue dashed line and circle markers. For instance the command,
plot(x, u(2,:), ‘g-^’)
will plot a graph between ‘x’ and ‘second row of matrix u’ using a green line with triangular markers and display it in a new figure window. Similarly, graphs can be plotted for the remaining rows of matrix u. To know more about the plot function, please refer to the following documentation: https://in.mathworks.com/help/matlab/ref/plot.html
In order to display all the graphs in the same figure window, you can use ‘hold on’ command. The following lines of code will display all the 3 graphs in the same figure window.
plot(x, u(1,:), 'b--o')
hold on
plot(x, u(2,:), 'g--^')
plot(x, u(3,:), 'r-*')
To know more about the hold command, please refer the following documentation: https://in.mathworks.com/help/matlab/ref/hold.html
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots 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!