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)
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;
Error: Invalid expression. Check for missing or extra characters.
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;

Risposta accettata

Walter Roberson
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()
You should probably be using the Symbolic Toolbox and subs or creating symfun
  1 Commento
Walter Roberson
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
v1 = 12.4440
%tramo2 2<x<4
v2=ra-w1*2+rb-w2
v2 = -7.5560
%tramo3 4<x<5
v3=ra-w1*2+rb-w2+rd
v3 = 0.0040
%ECIACIONES DE MOMENTO
m1=-30*x.^2+(-(3/5)*rb+(500/5))*x
m1 = 
m2=rb*(x-2)-(120*(x-1))+(-3*rb+500)*(x/5)
m2 = 
m3=-20*(x-4)+rb*(x-2)-120*(x-2)+(-3*rb+500)*x/5
m3 = 
EV=[v1;v2;v3];
EM=[m1;m2;m3];
%graficas de momentos y cortantes
funv1 = vectorize(string(v1))
funv1 = '12.444'
funm1 = vectorize(m1)
funm1 = '(3612266892369697.*x)./70368744177664 - 30.*x.^2'
x=0:0.1:2;
V1=eval(funv1)
V1 = 12.4440
M1=eval(funm1)
M1 = 1×21
0 4.8333 9.0667 12.7000 15.7334 18.1667 20.0000 21.2334 21.8667 21.9001 21.3334 20.1667 18.4001 16.0334 13.0668 9.5001 5.3334 0.5668 -4.7999 -10.7665 -17.3332
x1=x;
funv2 = vectorize(string(v2))
funv2 = '-7.556'
funm2 = vectorize(m2)
funm2 = '(27365525001391297.*x)./2199023255552000 - 21111./500'
x=2:0.1:4;
V2=eval(funv2)
V2 = -7.5560
M2=eval(funm2)
M2 = 1×21
-17.3332 -16.0888 -14.8443 -13.5999 -12.3554 -11.1110 -9.8666 -8.6221 -7.3777 -6.1332 -4.8888 -3.6444 -2.3999 -1.1555 0.0890 1.3334 2.5778 3.8223 5.0667 6.3112 7.5556
x2=x;
funv3 = vectorize(string(v3))
funv3 = '0.004'
funm3 = vectorize(m3)
funm3 = '78889./500 - (16614940109648703.*x)./2199023255552000'
x=4:0.1:5
x = 1×11
4.0000 4.1000 4.2000 4.3000 4.4000 4.5000 4.6000 4.7000 4.8000 4.9000 5.0000
V3=eval(funv3)
V3 = 0.0040
M3=eval(funm3)
M3 = 1×11
127.5556 126.8000 126.0445 125.2889 124.5334 123.7778 123.0222 122.2667 121.5111 120.7556 120.0000
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;
Error using plot
Vectors must be the same length.
subplot(2,1,1);plot(x,Vt);title('diagrama momento');xlabel('x(m)');ylabel('m(nm)');grid on;

Accedi per commentare.

Più risposte (1)

Image Analyst
Image Analyst il 22 Mag 2023

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by