I am receiving an Error using plot

조회 수: 2 (최근 30일)
Ibraheem
Ibraheem 2025년 2월 24일
편집: Walter Roberson 2025년 2월 24일
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)')

채택된 답변

Star Strider
Star Strider 2025년 2월 24일
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
Ibraheem
Ibraheem 2025년 2월 24일
thank you very much
Star Strider
Star Strider 2025년 2월 24일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by