I am receiving an Error using plot

5 Ansichten (letzte 30 Tage)
Ibraheem
Ibraheem am 24 Feb. 2025
Bearbeitet: Walter Roberson am 24 Feb. 2025
I am getting this error when running my code
Error using plot
Data must be numeric, datetime, duration, categorical, or an array convertible to double.
Error in pendulun (line 27)
plot(t,y1, t,y2)
m1 = 49/1000;
m2 = 31/1000;
l1 = 0.5;
l2 = 0.5;
M = 1; % mlower/ m upper
l = 100/100; %lu/ l lower
A = (-9.8/1.0)*[(-(l + M*l +M)) M ; 1 -1]; % g/ l lower
w = eig(A);
[Aa,Bb] = eig(A);
omg = sqrt(w);
fre = omg/(2*pi);
nA = 1* A;
%nA = [2 -1; -1 2];
wn = eig(nA);
[S, V]= eig(nA);
syms x(t)
coslam = [(cos(sqrt(V(1,1))*t)) 0 ; 0 (cos(sqrt(V(2,2))*t))];
sinlam = [(sin(sqrt(V(1,1))*t)) 0 ; 0 (sin(sqrt(V(2,2))*t))];
Solu = (S*coslam*(inv(S))*[1/100 ;1/100]) + (S* sinlam* (sqrtm(inv(V)))*(inv(S))*[0;0]);
hold on
t = linspace (0,10,1000000);
y1 = Solu(1);
y2 = Solu(2);
plot(t,y1, t,y2)
title (['Plot of y_{1}(t) and y_{2}(t) of the pendulum' ...
' l2 = 1m, M =0.6327, L= 1'])
grid
xlabel ('Time (s)')
ylabel('Distance(m)')
legend('y1(t)','y2(t)')

Akzeptierte Antwort

Star Strider
Star Strider am 24 Feb. 2025
Use the matlabFunction function, evaluate it with ‘t’ and then plot —
m1 = 49/1000;
m2 = 31/1000;
l1 = 0.5;
l2 = 0.5;
M = 1; % mlower/ m upper
l = 100/100; %lu/ l lower
A = (-9.8/1.0)*[(-(l + M*l +M)) M ; 1 -1]; % g/ l lower
w = eig(A);
[Aa,Bb] = eig(A);
omg = sqrt(w);
fre = omg/(2*pi);
nA = 1* A;
%nA = [2 -1; -1 2];
wn = eig(nA);
[S, V]= eig(nA);
syms x(t)
coslam = [(cos(sqrt(V(1,1))*t)) 0 ; 0 (cos(sqrt(V(2,2))*t))];
sinlam = [(sin(sqrt(V(1,1))*t)) 0 ; 0 (sin(sqrt(V(2,2))*t))];
Solu = (S*coslam*(inv(S))*[1/100 ;1/100]) + (S* sinlam* (sqrtm(inv(V)))*(inv(S))*[0;0]);
Solufcn = matlabFunction(Solu)
Solufcn = function_handle with value:
@(t)[cos(t.*5.7844008256047).*5.0e-3+cos(t.*2.395977272167595).*4.999999999999999e-3;cos(t.*5.7844008256047).*(-2.071067811865475e-3)+cos(t.*2.395977272167595).*1.207106781186547e-2]
hold on
t = linspace (0,10,1000000);
Solv = Solufcn(t)
Solv = 2×1000000
0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
y1 = Solv(1,:);
y2 = Solv(2,:);
plot(t,y1, t,y2)
title (['Plot of y_{1}(t) and y_{2}(t) of the pendulum' ...
' l2 = 1m, M =0.6327, L= 1'])
grid
xlabel ('Time (s)')
ylabel('Distance(m)')
legend('y1(t)','y2(t)')
.
  2 Kommentare
Ibraheem
Ibraheem am 24 Feb. 2025
thank you very much
Star Strider
Star Strider am 24 Feb. 2025
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by