n = 2; mod(factorial(n-1)+1,n) % you get zero, if n is a prime; otherwise, you get a non-zero numberThere are a few special prime numbers
N = 1000;Because the built-in function
pl = primes(N); % get the list of all primes less than or equal to N
for p=pl % loop over all primes up to N
% check whether p is a Wilson prime
end
factorial
can only be used for numbers less than 19
(forget about the much slower alternative using symbolic numbers),
you have to apply the modulus frequent enough.
dsolve
, whose general solution is
diff(y,x,2)
for the second derivative of y
with respective to x
, and similarly for higher order derivatives. Notice
that the constants in the general solution could be different from the above expression (but still equivalent).
ode45
, and compare the error between the numerical solution and
the exact solution (by evaluating at the vector of time from the numerical solver).
options = odeset('refine',8);
in your code, and then ode45( ..., options)
to get enough points/resolution for plotting.
This system is chaotic, because the solution could be completely different in the long run,
if the initial condition is changed slightly. Compare the (numerical) solution at the end of the time
interval options = odeset('refine',8);
in your code, and then ode45( ..., options)
to get enough points/resolution for plotting.
You can also change the initial condition slightly, to see how the final solution at Once you find the right initial condition
%% Periodic solution of the non-linear ODE y' = -y^3 + sin (t)
% save this file as per_nlode.m
function per_nlode
y0 = fzero(@(y0)sol_diff(y0),0);
function yd = sol_diff(y0)
% return the difference y(2*pi)-y(0) of solutions to y' = -y^3 + \sin t, with input y(0)=y0