when i run code i get Error using grafic Error: Invalid expression. Check for missing or extra characters. i don´t know how to fix it, help me
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
daniel moreno
il 21 Mag 2023
Commentato: Walter Roberson
il 22 Mag 2023
clc; clear;
A=0.0175*0.3+0.01*0.3156+0.0175*0.3;
L=5;
x=0:0.1:5;
%REACCIONES
ra=51.333;
rb=81.111;
rd=7.56;
R=[ra;rb;rd];
w1=60;
w2=20;
%ECUACIONES DE CORTANTE
%tramo1 0<x<2
v1=ra-w1*2+rb;
%tramo2 2<x<4
v2=ra-w1*2+rb-w2;
%tramo3 4<x<5
v3=ra-w1*2+rb-w2+rd;
%ECIACIONES DE MOMENTO
m1=-30*x.^2+(-(3/5)*rb+(500/5))*x;
m2=rb*(x-2)-(120*(x-1))+(-3*rb+500)*(x/5);
m3=-20*(x-4)+rb*(x-2)-120*(x-2)+(-3*rb+500)*x/5;
EV=[v1;v2;v3];
EM=[m1;m2;m3];
%graficas de momentos y cortantes
x=0:0.1:2;V1=eval(vectorize(v1));M1=eval(vectorize(m1));x1=x;
x=2:0.1:4;V2=eval(vectorize(v2));M2=eval(vectorize(m2));x2=x;
x=4:0.1:5;V3=eval(vectorize(v3));M3=eval(vectorize(m3));x3=x;
x=[x1 x2 x3];
Vt=[V1 V2 V3];
Mt=[M1 M2 M3];
subplot(2,1,1);plot(x,Vt);title('diagrama cortante');xlabel('x(m)');ylabel('v(n)');grid on;
subplot(2,1,1);plot(x,Vt);title('diagrama momento');xlabel('x(m)');ylabel('m(nm)');grid on;
0 Commenti
Risposta accettata
Walter Roberson
il 21 Mag 2023
v1 is purely numeric. vectorize() expects to be passed a string scalar or a character vector or a symbolic expression (or array of those) or a symfun .
When you pass a numeric value such as in v1 to vectorize(), it takes char() of the numeric value. Your v1 value is 12.444 so it takes char(12.444) which is control-L, the ASCII and Unicode formfeed character. https://www.compart.com/en/unicode/U+000C . You then eval() the formfeed character which MATLAB says is an error.
This is just one of the many ways that eval() can produce errors. You should rarely rarely rarely use eval()
1 Commento
Walter Roberson
il 22 Mag 2023
Your v1, v2, v3 are independent of x, so if you take care to get the datatypes correct, eval() of vectorize() of them is going to give a single point for each, not a constant for each different x value. Then when you go to plot the values, you have a problem because [V1 V2 V3] is going to be a vector formed from the three scalars, and that is not going to fit to plot against the [x1 x2 x3]
syms x
A=0.0175*0.3+0.01*0.3156+0.0175*0.3;
L=5;
%x=0:0.1:5;
%REACCIONES
ra=51.333;
rb=81.111;
rd=7.56;
R=[ra;rb;rd];
w1=60;
w2=20;
%ECUACIONES DE CORTANTE
%tramo1 0<x<2
v1=ra-w1*2+rb
%tramo2 2<x<4
v2=ra-w1*2+rb-w2
%tramo3 4<x<5
v3=ra-w1*2+rb-w2+rd
%ECIACIONES DE MOMENTO
m1=-30*x.^2+(-(3/5)*rb+(500/5))*x
m2=rb*(x-2)-(120*(x-1))+(-3*rb+500)*(x/5)
m3=-20*(x-4)+rb*(x-2)-120*(x-2)+(-3*rb+500)*x/5
EV=[v1;v2;v3];
EM=[m1;m2;m3];
%graficas de momentos y cortantes
funv1 = vectorize(string(v1))
funm1 = vectorize(m1)
x=0:0.1:2;
V1=eval(funv1)
M1=eval(funm1)
x1=x;
funv2 = vectorize(string(v2))
funm2 = vectorize(m2)
x=2:0.1:4;
V2=eval(funv2)
M2=eval(funm2)
x2=x;
funv3 = vectorize(string(v3))
funm3 = vectorize(m3)
x=4:0.1:5
V3=eval(funv3)
M3=eval(funm3)
x3=x;
x=[x1 x2 x3];
Vt=[V1 V2 V3];
Mt=[M1 M2 M3];
subplot(2,1,1);plot(x,Vt);title('diagrama cortante');xlabel('x(m)');ylabel('v(n)');grid on;
subplot(2,1,1);plot(x,Vt);title('diagrama momento');xlabel('x(m)');ylabel('m(nm)');grid on;
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Special Values in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

