Can you help plot graph please
1 view (last 30 days)
Show older comments
ebru on 22 Nov 2022
Answered: Amey Waghmare on 25 Nov 2022
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)
%ilk satır hesaplamaları
u(1,j) = 0.21-0.14* x(j);
%ikinci satir hesaplamalari
for j = 2:c-1
u(2,j) = (u(1,j-1)+u(1,j+1)) / 2;
%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);
for i = 1:r
for j = 1:c
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')
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
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!