singularity at differential equation with MATLAB - matlab

I can't solve this differential equation by ode45 beacause it has sigularity.
xy"=3xcos(x)+sin(x) ; x(0)=0 , x'(0)=0
can you help me to write ode45 function?

You can use the sinc(x) function, which is defined as sin(π*x)/(π*x), except at x=0 where its value is 1. So, you can rewrite your ODE as:
y'' = 3*cos(x) + sinc(x/π)
which ode45 shouldn't have any trouble solving.

Related

How can I find the total harmonic distortion of a nonlinear signal. Using matlab

How can I find the total harmonic distortion of a nonlinear signal. For example, Forced Van der pol Oscillator with code as shown below. I have tried the 'thd' function in matlab but I guess I'm missing somethings.
This is the equation
x''-mu(1-x^2(t))x'(t)+x(t)=Pcos(w*t)
function vdpo()
t=0:0.001:10
mu=2
x0=-2;
v0=2;
p=10; w=7;
[t,x]= ode45(#f, t, [x0,v0])
function dxdt=f(t,x)
dxdt1=x(2); dxdt2= mu(1-x(1)^2)*x(1)+p*cos(w*t);
dxdt=[dxdt1 ;dxdt2];
end
end
Try the code below, in which function f(t,x) is our ODE equations and we call function ode45 to use Runge-Kutta methods to solve it.
function [x]=vdpo()
t=0:0.001:10
mu=2
x0=-2;
v0=2;
p=10; w=7;
[t,x]= ode45(#f, t, [x0,v0])
function dxdt=f(t,x)
dxdt1=-x(2)-x(1)+(x(1)^3)/3; dxdt2=-x(1)+p*cos(w*t);
dxdt=[dxdt1 ;dxdt2];
end
end
However, it is actually a math problem rather than a programming problem. The first thing that we have to do is to transform the equations into a more convenient form by defining y=x'+((x^3)/3-x)*mu, then we have 2 First Order Ordinary Differential Equations so we could call ode45 to solve it. I looked them through at here(page2).
By calling
X=vdpo();
x=X(:,1);
thd(x)
we could get an answer like:
p.s. NOT CERTAIN about THD part.

How to solve or approximately solvea differential equation with a integral item in matlab

I want to solve the equation group like
\frac{dx_1(t)}{dt}&=(1-\int_0^t x_1(t) dt)x_2+x_1;
\frac{dx_2(t)}{dt}&=(1-\int_0^t x_2(t) dt)x_1+x_2.
Can I directly use the methods in Matlab to solve this problem? I tried ode45 but failed.

How to solve differential equation in matlab

How can I show that y(t)=Yo/Yo+(1-Yo)e^-at is the solution of the differential equation dy/dt=ay(1-y) using MATLAB. What function should I use?
if you want to simulate the results use the ode's family
https://www.mathworks.com/help/matlab/ref/ode45.html
else you can define your equation in syms and use diff
https://www.mathworks.com/help/symbolic/diff.html
other wise you can solve it numerically

Solve differential equation with two variables in Simulink

I have a differential equation of the form:
xs'' = rhs * theta
to solve in Simulink, where xs and theta are variables and rhs is a numerical constant. So far, I've got this:
but it's incomplete and I feel it is wrong. How can I simulate this equation in Simulink?
Regards
This works as expected:
Thanks to #Ander Biguri!

Solve equation Matlab

Hy can anyone can tell me how i can solve this equation
2xJ1(x) − J0(x) = 0
where J1 and J0 are the Bessel function
in Matlab without using the fsolve command
You can use fzero to find the zeros if and only if the curve crosses the x-axis. So
fzero(#(x)(2*x*besselj(1,x)-besselj(0,x)),x0)
will give you the zero close to x0.
See this answer of mine for an explanation of when and why fzero fails (although it won't for a Bessel function, it's good to be aware) and the tradeoffs with fsolve.