plotting a function that contains a symbol(x)

3 views (last 30 days)
I'm writing a function that plots the position of a front tire, rear tire, chassis and the rotation of the chassis of a motorbike after hitting a bump. I was successfully able to do this but then I thought it would be cool to be able to put a function into the forces acting on the tires so instead of a simple initial condition that acts as the bump the function could act as a "road" pushing up in the bike. I'm not sure If I'm taking the right approach to do this but its impossible for me to check because I cant figure out how to plot the new data. Ill attach the function I made containing my EOM and the file that solves these equations using the euler method. Thanks!
function dx = projectmatrix2(T,u)
k1 = 35; %spring coefficient between tire and ground
k2 = 30; %front spring coefficient
k3 = 20; %rear spring coefficient
m1 = 50; %mass of front tire
m2 = 50; %mass of rear tire
m3 = 500; %mass of chassis
c1 = 10; %front damping coefficient
c2 = 10; %rear damping coefficient
r = 1.25; %horizontal distance from COG(chassis) to vertical suspension forces(ft)
b = 3; %width of chassis(ft)
h = 1; %height of chassis (ft)
I = (1/12)*m3*(b^2+h^2); %moment of inertia
L = 3; %distance from COG(tire) to COG(chassis)(ft)
v = 20; %velocity of bike in ft/s
T = (2*r)/v;
syms x
roadfunction1 = x^3;
roadfunction2 = (x-T)^3;
dx = sym(zeros(8,1));
dx(1) = u(2);
dx(2) = (-k1*u(1)-c1*(u(2)-u(6))+k2*(-L-u(1)+u(5))+roadfunction1)/m1;
dx(3) = u(4);
dx(4) = (-k1*u(3)+(-u(3)-L+u(5))*k3-(u(4)-u(6))*c2+roadfunction2)/m2;
dx(5) = u(6);
dx(6) = ((-u(1)-L+u(5))*k2 - (u(2)-u(6))*c1 + (-u(3)-L+u(5))*k3-(u(4)-u(6))*c2)/m3;
dx(7) = u(8);
dx(8) = (-r*k2*(-u(1)-L+u(5))-r*c1*(u(2)-u(6))+r*k3*(-u(3)-L+u(5))+r*c2*(u(4)-u(6)))/I;
end
%Euler method
Tsim = 10;
h = .1;
n = Tsim/h;
%X = [0;0;0;0;0;0;0;0];
X = sym(zeros(8,1));
t = zeros(1,n);
for i=1:n-1
t(i+1) = t(i) + h;
X(:,i+1) = X(:,i) + h * projectmatrix2(t(i),X(:,i));
end
fplot(X(1,:),t)
% plot(t,X(1,:),'b*-')
% hold on
% plot(t,X(3,:),'g*-')
% plot(t,X(5,:),'r*-')
% plot(t,X(7,:),'y*-')
% hold off
  1 Comment
Andrew Newell
Andrew Newell on 19 Apr 2017
It's not clear what you are trying to plot. The array X is full of functions of a symbolic variable x that does not depend on t.

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!