Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone please help me get this matlab code right. x0=[0.1,0.1]; ts=[0,5]; [

ID: 1862126 • Letter: C

Question


Can someone please help me get this matlab code right.


x0=[0.1,0.1];

ts=[0,5];

[t,x]=ode45('f1_93',ts,x0);

plot(t,x(:,1), t,x(:,2))

title('problem 1.93'); grid on;

xlable('time (s)');ylabel('displacement (m), velocity (m/s)');


%-------------------------------------------------

function [xdot] =f1_93 t,x;

%computes derivatives for the state-space ODEs

m=250;

k=3000;

mu=0.05;

g=9.81;

angle = 20*pi/180;

xdot(1) = x(2);

xdot(2) = -k/m*x(1) - mu*g*cos(angle)*sign(x(2));

%use the sign function to improve computation time

xdot= [xodt(1); xdot(2)];

Explanation / Answer

One mistake is the last line xodt(1) it should be xdot(1)


I do not have matlab to test the code but I believe one mistake you are making is in


xdot(1) = x(2);

xdot(2) = -k/m*x(1) - mu*g*cos(angle)*sign(x(2));

is it x0 you are referring to and not x?