how to solve first order nonlinear ode45 in a loop?

I am trying to solve this nonlinear ode in a loop, first, I tried to use dsolve but it was unable to find explicit solution. Now I tried to use ode45 with limited span but it does not work also, please guys help.
imax = 50; npeop = 10; dt = 0.01
omfoot = 0.5*pi/2 + + randn(1,npeop)*0.1;
om = 0.2*pi;
Phi_i = 0.5*omfoot.*dt;
theta(npeop,1) = Phi_i;
u9 = zeros(npeop,imax);
theta = zeros(npeop,imax+1);
for i = 1:imax
syms theta_t(xt)
A = sqrt(xt^2 +xt^2/om);
Psi = asin(xt/A);
ode = (diff(theta_t,xt)) == Phi_i + 16*A*sin( Psi - theta_t + pi/2);
cond = theta_t(0) == theta(:,i);
xt_span = [u9(i) 0.001];
f = ode45(@(xt,theta_t) ode,xt_span,cond);
end

Answers (1)

Your code has some flaws:
(1) theta(npeop,1) = Phi_i; is to be: theta(1:npeop,1) = Phi_i;
(2) Moreover, there are several undefined variables (om, u9, xspan) used within the loop that need to be defined in order to run your code.
(3) The variable ode representing DE can be defined via function file or function handle without syms that would be much faster and more efficient.
Good luck.

Products

Release

R2018a

Asked:

on 19 Aug 2019

Edited:

on 19 Aug 2019

Community Treasure Hunt

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

Start Hunting!