×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How do I sovle a non-homogenous 1st order ODE?

How do I sovle a non-homogenous 1st order ODE?

How do I sovle a non-homogenous 1st order ODE?

(OP)
How do you solve:

dx/dt= b(t)-x(t)

where b(t) is a step function

RE: How do I sovle a non-homogenous 1st order ODE?

I had to solve a similar problem, solving

dx/dt= (b(t)-x(t)/tau

where b(t) is a step function.

To solve i wrote 3 files.  Two files for the step signal, i.e. the stepsignal function and the r.h.s function that is used in it.
The third file(script) solves dx/dt= (b(t)-x(t)/tau by calling the other two files and then plots
dx/dt= (b(t)-x(t))/tau and the step signal on the same plot to compare the two.

These three functions/script are shown below.  Hope this is of some use.

Andrew Boardman
MID RNR



function dxdt=steprhs(t,x)
tau=1;
dxdt=(stepsignal(t,5)-x)/tau; %uses function stepsignal.m
%
%Written by
%Andrew Boardman 11/03/03
%
%This function is the
%rhs of the ode  dy/dx = ( b(t) - x(t) ) / tau
%where b(t)=f step (t,5)
%the rhs is used by solvestepsignal.m


function signal=stepsignal(t,t0)
 %function signal = stepsignal(t,t0)
 %
 %if t<t0 we return 0, otherwise we return 1
 %
if t<t0
    signal=0;
else
    signal=1;
end
%
%written by
%Andrew Boardman 11/03/03
%
%This function is the step-function
%f step (t,t0) as defined on sheet 4
%This function is solved and plotted
%by solvestepsignal.m



t=0:0.1:20;
for i=1:length(t)
    s(i)=stepsignal(t(i),5);
end
plot(t,s,'-r')
grid on
hold on
xlabel('t')
ylabel('input and output response')
 %
[t,x]=ode45('steprhs',[0 20],0);
plot(t,x,'-o')
legend('stepsignal(t,5)','x(t)')
hold off
%
%written by
%Andrew Boardman 11/03/03
%
%This file solves and plots the
%ode  dy/dx = ( b(t) - x(t) ) / tau
%where b(t)=f step (t,5)
%also plots f step (t,5) against t

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources