MATLAB: Solving non homogenous differential equations numerically using ode45 etc nonhomogenousode45 How is a non homogenous differential equation solved in MATLAB using ode45 or ode23. I have a function like:- dmdt = a*exp(Asin(wt) + (2-m)^2); Can I obtain the numerical solution for this? Thanks in advance Best Answer Sarah, yes you can. The typical approach for such an example is to create two functions: function my_EOM() a = 1; A = 1; w = 1; fun = @(w,x) sin(w.*x); param = {a; A; w; fun}; IC = -1; [t,m] = ode45(@EOM,[0 1],IC,[],param); plot(t,m) xlabel('t') ylabel('m') grid end function dmdt = EOM(t, m, param) a = param{1}; A = param{2}; w = param{3}; fun = param{4}; dmdt = a*exp(A*fun(w,t) + (2 - m)^2); endSave both functions in the same .m-file and with name my_EOM.m. Execute and enjoy. Related SolutionsMATLAB: How to normalize unit vector in ode45 function mainw = [0;0;1]; % rotates around z axis, with angular velocity 1 rad/si0 = [1/2;1/2;1/sqrt(2)]; % initial unit vectortspan = [0,100]; % time spanopts = odeset('RelTol',1e-8,'AbsTol',1e-8);[t,i] = ode45(@(t,i)exampleFun(t,i,w),tspan,i0,opts); % use ode45 to solve for new unit vectorabsi=i(:,1).^2+i(:,2).^2+i(:,3).^2;plot(t,absi)endfunction idot = exampleFun(t,i,w)idot = cross(w,i);endBetter ?Best wishesTorsten. MATLAB: Trying to implement nonlinear ODE equation The third equation will bedz(3) = (-K*F)*y(2)/sqrt(y(1)^2+y(2)^2)withdz = zeros(3,1); Related QuestionSolving coupled differential equations
Best Answer