Please help me !!! Error using * Inner matrix dimensions must agree. Error in GRAFICA_TOTAL_2 (line 40) Volum= (2*T.^2*q1​+q2*T.^3*(​(1/2-(A1*(​A2-A3))/2*​C*Ro*G(A1+​A2-A3))))

1 vue (au cours des 30 derniers jours)
clear;clc;
Ro=1; G=981; A1=100; A2=150; A3=125;
% *********************Hallando Desplazamiento**************************
CC = input ('Ingrese la COMPLIANCIA (cm3/cmH2O)DEL PULMON C = ')
subplot (2,2,1);syms t ;t=0:0.1:3; Q =(t+0.1*sin(8*t));
% stairs(t,Q); hold on % hold off
plot(t,Q)
legend('t+0.1*sin(8t)')
title ("FLUJO/CAUDAL Q, VARIANTE RESPECTO AL TIEMPO")
xlabel("Tiempo (seg)")
ylabel("Flujo ó Caudal en LPM")
% ***********************Hallando Aceleración***************************
C= CC/981;syms T
Q = (T+0.1*sin(8*T));
X=((C*Ro*G*Q*T*(A1+A2-A3)/C*Ro*G*A1*A3)-Q*T*A1*(A2-A3)/(C*Ro*G*A1*A3));
subplot(2,2,2);T=0:0.01:3; Acel= diff (X,2); % Derivada de segundo orden
Acel=double(subs(Acel)); % stairs(T,Acel);% hold off
hold on
plot(T,Acel)
title ("ACELERACIÓN RESPECTO AL TIEMPO ")
xlabel("Tiempo (seg)")
ylabel("Aceleracion en cm/seg2")
%*******************Hallando VOLUMEN****************************
C= CC/981; syms T
Q = (T+0.1*sin(8*T)); T=0:0.01:3;
q=double (subs(Q));
q1=diff(Q)
ql=double(subs(Q));
q2=diff (Q,2)
q2=double(subs(Q));
subplot (2,2,3)
% Volum = Acel*(T.^2/2)*((A1*A3)/(A1+A2-A3)); pretty (Volum);
Volum= (2*T.^2*q1+q2*T.^3*((1/2-(A1*(A2-A3))/2*C*Ro*G(A1+A2-A3))))
% Volum= T.^2+ T.^2*cos(T) - 0.5*sin(T.^4)
hold on
grid on
vol= eval (Volum)
plot(T,Vol)
%**************Hallando PRESIÓN******************
syms T
Q = (T+0.1*sin(8*T)); T=0:0.1:3;
Pres=(Volum*((A1+A2-A3)/A1- C*Ro*G(A1+A2-A3)-A1(A2-A3)/C*Ro*G*A1))/ A2-A3;
plot(t,Pres)
title ("PRESION CON RESPECTO AL TIEMPO ")
xlabel("Tiempo (seg)")
ylabel("Presión en cm-H2O")

Réponse acceptée

Walter Roberson
Walter Roberson le 13 Oct 2019
Volum= (2*T.^2*q1+q2*T.^3*((1/2-(A1*(A2-A3))/2*C*Ro*G(A1+A2-A3))))
q2 is 1 x 301. T is 1 x 301. The * operator is algebraic matrix multiplication. In the expression A*B, A and B must be 2 dimensional and size(A,2) must be the same as size(B,1) and the size of the result is size(A,1) by size(B,2) . 1 x 301 * 1 x 301 has 301 on the left and 1 on the right, and that is not compatible.
Chances are that you want .* instead of *
G(A1+A2-A3)
That is an indexing request, but G is a scalar, and A1+A2-A3 is 125, so you are asking for the 125th element of a scalar. Perhaps you want a multiplication in there.
syms T
Q = (T+0.1*sin(8*T)); T=0:0.01:3;
Using a variable as a symbolic variable and then replacing the variable with a numeric value quite often leads to errors: it is too easy to get confused about whether the name refers to the symbolic or the numeric value in any particular context.
vol= eval (Volum)
It is always a mistake to eval() a symbolic expression. Symbolic expressions are in a language which is not exactly MATLAB and which are not exactly the underlying symbolic MuPAD language either. eval() is going to malfunction. You should subs() instead.
Your expression for Volum involves a mix of the numeric T and the symbolic T. After the above fixes, Volum is a symbolic expression the same size as T (1 x 301), each entry of which involves the symbolic variable T. When you subs() or eval() to substitute the numeric T in place of the symbolic T, substitution is defined to replace each symbolic variable with the entire contents of the numeric variable. So you end up with each of the 301 entries in Volum expanded to 301 entries, for a total of 90301 numeric entries. eval() and subs() do not proceed element-by-element.
You would not have this problem if you stuck with a purely symbolic T in building the expressions, and then later subs() the list of numeric values for the single symbolic expression. As I wrote above, "Using a variable as a symbolic variable and then replacing the variable with a numeric value quite often leads to errors"
  4 commentaires
César Arturo Niño Carmona
Undefined function or variable 'Vol'.
Error in GRAFICA_TOTAL_3 (line 45)
plot(T,Vol)
The last one !!
César Arturo Niño Carmona
Error using plot
Vectors must be the same length.
Error in GRAFICA_TOTAL_3 (line 45)
plot(T,vol)
I notice V, vs v,
Now, this is the message !! Please help me, It's very neccesary to me.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Formula Manipulation and Simplification dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by