MATLAB: I can’t plot this one

plot

clear clc
xss=0.01;
omegaf = 40;
omegan = 20;
n=0.1;
syms x(t) A B
v(t) = diff(x,t);
x0 =0.05;
v0 =2;
eq1 = xss * cos(omegaf*t) + (A*sin(omegan*t) +B* cos(omegan*t))*exp(-n*omegan*t) == x;
eq2 = diff(eq);
eq3 = subs( eq1 , [x(t),t] , [x0,0]);
eq4 = subs( eq2 , [v(t),t] , [v0,0]);
[D,C] = equationsToMatrix([eq3,eq4],[A,B]);
Res = linsolve(D,C);
eq1 = subs(eq1, [A,B] ,[Res(1),Res(2)]);
t=0:4;
plot(t,eq1)

Best Answer

The ‘eq1’ expression is not written correctly with respect to its being a function off one variable.
Try this:
xss=0.01;
omegaf = 40;
omegan = 20;
n=0.1;
syms x(t) A B
v(t) = diff(x,t);
x0 =0.05;
v0 =2;
eq1 = xss * cos(omegaf*t) + (A*sin(omegan*t) +B* cos(omegan*t))*exp(-n*omegan*t) == x;
eq2 = diff(eq1);
eq3 = subs( eq1 , [x(t),t] , [x0,0]);
eq4 = subs( eq2 , [v(t),t] , [v0,0]);
[D,C] = equationsToMatrix([eq3,eq4],[A,B]);
Res = linsolve(D,C);
eq1 = subs(eq1, [A,B] ,[Res(1),Res(2)])
eq1 = lhs(eq1); % Use Only Left-Hand-Side For 'eq1’
% t=0:4;
fplot(eq1, [0 4])
This plots only the left-hand-side of the expression (using the lhs function), and uses fplot rather than plot.