# I dont know how to integrate a function with variables depending on time

5 views (last 30 days)

Show older comments

Diego Martínez Caldas
on 26 Jan 2024

Commented: Diego Martínez Caldas
on 26 Jan 2024

I have a function

syms theta(t)

fmov(t) = (2943*sin(theta(t)))/200 - (27*sin(2*theta(t))*diff(theta(t), t)^2)/4 + (3*(9*cos(theta(t))^2 + 2)*diff(theta(t), t, t))/2

Which I want to integrate twice respect to time in order to obtain a function with just theta(t) and t as variables.

And I only have the min and max values of theta(t). It is an angle and range is from 60º until 0º.

I dont know what the final time will be and starting time is 0.

Can anyone help me?

##### 3 Comments

Torsten
on 26 Jan 2024

Edited: Torsten
on 26 Jan 2024

I have a function

fmov(t) =

(2943*sin(theta(t)))/200 - (27*sin(2*theta(t))*diff(theta(t), t)^2)/4 + (3*(9*cos(theta(t))^2 + 2)*diff(theta(t), t, t))/2

fmov(t) is a given function of t and it equals the expression

(2943*sin(theta(t)))/200 - (27*sin(2*theta(t))*diff(theta(t), t)^2)/4 + (3*(9*cos(theta(t))^2 + 2)*diff(theta(t), t, t))/2

, so e.g.

sin(t) = (2943*sin(theta(t)))/200 - (27*sin(2*theta(t))*diff(theta(t), t)^2)/4 + (3*(9*cos(theta(t))^2 + 2)*diff(theta(t), t, t))/2

for fmov(t) = sin(t) ?

?

John D'Errico
on 26 Jan 2024

### Accepted Answer

Sam Chak
on 26 Jan 2024

You can utilize the odeToVectorField() function to convert the 2nd-order differential equations to a system of 1st-order differential equations. Once you have the 1st-order form, you can then apply the ode45() solver to solve the problem.

syms theta(t)

myODE = (2943*sin(theta))/200 - (27*sin(2*theta)*diff(theta, t)^2)/4 + (3*(9*cos(theta)^2 + 2)*diff(theta, t, t))/2 == 0;

[V, S] = odeToVectorField(myODE)

M = matlabFunction(V, 'vars', {'t', 'Y'})

tspan = [0 30];

Y0 = [3*pi/4 0];

sol = ode45(M, tspan, Y0);

fplot(@(t) deval(sol, t, 1), tspan), grid on

xlabel('t'), ylabel('\theta(t)')

### More Answers (0)

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!