Hi I am plotting my matrix and the x values are not what they are suppose to be. There is an example of the plot I have to make and the x-values should be from 0 to L (L is defined in my work) with 100 evenly spaced points. But I am getting that its from 1 to 5 can somepne help me please my work is below. My T_matrix is the y axis.
%initializing parameters
k=20;
P=0.1;
h=490;
A_c=4.4*10^-4;
L=0.08;
T_b=400;
T_inf=900;
nodes=5;
%build Coefficient and Constants (right hand side of eqn) matrices
T_1 = T_b;
dx = L/4;
x = dx*.5;
m = sqrt((h*P)/(k*A_c));
M = [ 1 0 0 0 0;
-1 (2+(m*dx)^2) -1 0 0;
0 -1 (2+(m*dx)^2) -1 0;
0 0 -1 (2+(m*dx)^2) -1;
0 0 0 -1 (2+(m*dx)^2)/2];
K = [T_b;
(m*dx)^2*T_inf;
(m*dx)^2*T_inf;
(m*dx)^2*T_inf;
(m*dx)^2/2*T_inf];
T = M\K;
%solove matrix
T_matrix= T;
%define analytical solution
T_analytic= ((cosh(m*(L-x)))/(cosh(m*L)))*(T_b-T_inf)+T_inf;
%plot matrix and analytic solutions
plot(T_matrix,'r')

7 comentarios

Daniel Pollard
Daniel Pollard el 17 de Dic. de 2020
Why would it plot the x-axis you want it to when you haven't told it to? plot takes x values and y values as inputs. If only one vector is given, then it assumes they're the y values and just plots them one after the other. T_matrix has 5 elements, so it plots the five points with x-coordinates of [1 2 3 4 5].
KALYAN ACHARJYA
KALYAN ACHARJYA el 17 de Dic. de 2020
" 0 to L (L is defined in my work) with 100 evenly spaced points"
L=0.08;
Is that 100 evenly spaced points?
Daniel Pollard
Daniel Pollard el 17 de Dic. de 2020
Editada: Daniel Pollard el 17 de Dic. de 2020
You have not got 100 evenly spaced points, the code
L=0.08;
defines one variable, L, which has a value of 0.08. For this application, you need the function linspace. Again, the documentation is excellent.
Edit Because in error I thought Kalyan was the OP. My points still stand but I've edited the wording.
Yogesh Bhambhwani
Yogesh Bhambhwani el 17 de Dic. de 2020
so how do i tell it to plot it the way i want to plot it
Daniel Pollard
Daniel Pollard el 17 de Dic. de 2020
See my previous comment about the plot and linspace commands. The information on those pages will help you and tell you exactly how the functions work, what arguments they take and they provide numerous examples for you to look through.
Yogesh Bhambhwani
Yogesh Bhambhwani el 17 de Dic. de 2020
So I read the document and looked at the Modify Lines After Creation section and I got an error saying that the vectorsmust be the same length
Daniel Pollard
Daniel Pollard el 17 de Dic. de 2020
As I mentioned in my first comment, T_matrix has 5 elements. You need 100 T values to plot against 100 x values. Alan Stevens seems to have a better grasp of your problem and has left an answer.
I recommend checking out the Matlab onramp course if you're going to be using Matlab more. It's free, and introduces the basics of the programming language and is highly recommended you do that when you're starting out with Matlab.

Iniciar sesión para comentar.

 Respuesta aceptada

Alan Stevens
Alan Stevens el 17 de Dic. de 2020
Editada: Alan Stevens el 17 de Dic. de 2020

1 voto

You need to define two different sets of x values. Your matrix solution results in 5 temperatures, so define
x = linspace(0,L,5)
and then plot T_matrix against this set of x's (preferably using points not lines).
You also need to define, say,
X = linspace(0,L,100)
and calculate the analytic values at these X's
T_analytic= ((cosh(m*(L-X)))/(cosh(m*L)))*(T_b-T_inf)+T_inf;
You can then plot XT_analytic against X (using lines).

Más respuestas (0)

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 17 de Dic. de 2020

Comentada:

el 17 de Dic. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by