# Need some help with solving diff.equ with matlab/simulink

• rularn
In summary, the conversation revolved around solving a differential equation using Matlab/Simulink. The equation was x'[t] + x[t] = a + Sin[b*t], with given values of a=1, b=1 and initial condition x(0)=2. The solution for x(t) was found to be 1/2 e^-t (-cos(t) e^t+sin(t) e^t+2 e^t+3). The transfer equation G(s) was also obtained from Laplace and was given as G(s) = (a/s+b/(b^2+s^2))/(s+1). The only issue was with the initial value, which was eventually resolved. The
rularn
Hi!

## Homework Statement

I have this x'[t] + x[t] = a + Sin[b*t] diff.equ that I would like to solve with matlab/simulink.
Let set a=1, b=1 and
x(0)=2

## Homework Equations

I know that x(t) = 1/2 e^-t (-cos(t) e^t+sin(t) e^t+2 e^t+3) and what it look like (see pic). I aslo got the transfer equ G(s) from Laplace and it should be:

G(s) = (a/s+b/(b^2+s^2))/(s+1),

## The Attempt at a Solution

The only thing I don't get right is the initial value as you can see at the pic. It also shows what it should look like. What do I do wrong?

It should be easier to use the transfer equ G(s), but I don't get that right either. Any suggestions?

http://img205.imageshack.us/img205/821/reglerth3.jpg

Thank you!

Last edited by a moderator:
Ah don't worry guys, I fixed it

I would suggest using the built-in functions in MATLAB/Simulink to solve your differential equation. You can use the "ode45" function for solving ordinary differential equations and the "laplace" function for finding the transfer function. Here is an example code that you can use:

a = 1; %set a=1
b = 1; %set b=1
x0 = 2; %set initial condition x(0)=2
syms x(t) %define x as a symbolic variable

%define the differential equation
ode = diff(x,t) + x == a + sin(b*t);

%convert the differential equation to a function handle
ode_fun = matlabFunction(ode);

%use "ode45" to solve the differential equation
[t,x] = ode45(ode_fun,[0 10],x0);

%plot the solution
plot(t,x)

%find the transfer function using "laplace" function
syms s %define s as a symbolic variable
G = laplace(ode,x,t,s);

%print the transfer function
disp(G)

I hope this helps you with solving your differential equation using MATLAB/Simulink. If you have any further questions or need clarification, please let me know.

## 1. What is the purpose of using MATLAB/Simulink for solving differential equations?

The purpose of using MATLAB/Simulink for solving differential equations is to provide a powerful and user-friendly tool for numerical computation and simulation. It allows for the efficient and accurate solution of complex mathematical problems, such as differential equations, which are commonly encountered in scientific and engineering fields.

## 2. Can I solve any type of differential equation using MATLAB/Simulink?

Yes, MATLAB/Simulink has a wide range of built-in functions and tools for solving different types of differential equations, including ordinary differential equations, partial differential equations, and delay differential equations. It also allows for the creation of custom functions for solving more specific or complex equations.

## 3. How do I use MATLAB/Simulink to solve a differential equation?

To solve a differential equation using MATLAB/Simulink, you will first need to define the equation in terms of dependent and independent variables. Then, you can use built-in functions or create your own custom function to solve the equation numerically. Finally, you can use the simulation and visualization tools in Simulink to analyze and interpret the results.

## 4. Are there any limitations to using MATLAB/Simulink for solving differential equations?

While MATLAB/Simulink is a powerful tool for solving differential equations, it does have some limitations. These include the need for a good understanding of the underlying mathematical concepts, potential errors resulting from numerical approximations, and the large amount of computational resources required for solving complex equations.

## 5. Can I use MATLAB/Simulink for applications other than solving differential equations?

Yes, MATLAB/Simulink has a wide range of applications in various fields, including data analysis, control systems, signal processing, and more. It can be used for numerical computation, simulation, and visualization of various types of mathematical models and systems, making it a versatile tool for many scientific and engineering applications.

• Engineering and Comp Sci Homework Help
Replies
2
Views
2K
• Engineering and Comp Sci Homework Help
Replies
1
Views
694
• Engineering and Comp Sci Homework Help
Replies
5
Views
2K
• Engineering and Comp Sci Homework Help
Replies
1
Views
1K
• Engineering and Comp Sci Homework Help
Replies
3
Views
2K
• Engineering and Comp Sci Homework Help
Replies
1
Views
525
• Engineering and Comp Sci Homework Help
Replies
4
Views
1K
• Engineering and Comp Sci Homework Help
Replies
3
Views
1K
• Engineering and Comp Sci Homework Help
Replies
1
Views
1K
• Engineering and Comp Sci Homework Help
Replies
2
Views
1K