1D 2nd-Order nonlinear differential eqn in Matlab

In summary, JAM is seeking help with solving a 2 point BVP using the Relaxation Method in MATLAB. They provide the problem and boundary conditions, and express their difficulty in finding a suitable code for this specific type of problem. The suggested steps for solving the problem in MATLAB involve defining variables, creating vectors, and using a for loop to update the values of N until they converge to a solution.
  • #1
jam_27
48
0
Hi all,

I am more into physics than maths and I need you guys to please help me out. Also I am new to programming in MATLAB. I have done some but still I consider myself a novice. I need to solve the problem in MATLAB.

So here is the problem.Its a 2 point BVP(boundary value problem) along a straight line ,say along x-axis , from -L to +L.


A*N''=B+(C*N)+(D*N^2)+f(N)


[prime denotes differentiation w.r.t x, N~N(x) , f(N) is a simple function of N, say log(N), All constants are known]

Now I need to solve this BVP for the following boundary conditions:N(-L)=B1 and N(L)=B2, Both B1 and B2 are also known.

The problem is that this particular equation needs to be solved using the "Relaxation Method" and Runge-Kutta/ Shooting method's are not considered suitable traditionally for this diffusion like problem.

Can anybody suggest me a code for this problem in Matlab. I haven't seen any function in MATLAB capable of solving NL BVP.

Please help.



JAM
 
Physics news on Phys.org
  • #2


Dear JAM,

Thank you for reaching out for help with your problem. Solving a 2 point BVP using the Relaxation Method in MATLAB can be done by following these steps:

1. Define the constants A, B, C, D, and f(N) as variables in MATLAB.

2. Define the boundary conditions N(-L) = B1 and N(L) = B2 as variables in MATLAB.

3. Create a vector of points along the x-axis from -L to +L using the linspace function in MATLAB.

4. Initialize a vector N with the same length as the vector of points, with all values set to 0.

5. Use a for loop to iterate through the vector of points and update the values of N using the relaxation method equation:

N(i) = (N(i-1) + N(i+1) - B - C*N(i) - D*N(i)^2 - f(N(i)))/A

where i is the index of the current point and N(i-1) and N(i+1) are the values of N at the previous and next points, respectively.

6. Repeat the for loop until the values of N converge to a satisfactory solution. This may take several iterations.

7. Plot the solution using the plot function in MATLAB, with the vector of points as the x-axis and N as the y-axis.

I hope this helps you solve your problem using the Relaxation Method in MATLAB. If you encounter any difficulties, please don't hesitate to ask for further assistance.

Best of luck,

 
  • #3


Hi JAM,

Solving nonlinear differential equations in MATLAB can be a bit tricky, but it is definitely doable. The first step would be to define your equation as a function in MATLAB. You can do this by using the "function" keyword and specifying the input and output variables. For example:

function dydx = my_eqn(x,y)
% This function defines the differential equation
% A*N''=B+(C*N)+(D*N^2)+f(N)

dydx = zeros(2,1); % initialize the output vector
dydx(1) = y(2); % first element of output vector is N'
dydx(2) = (B + C*y(1) + D*y(1)^2 + f(y(1)))/A; % second element is N''

Once you have defined your equation, you can use MATLAB's built-in "ode45" function to numerically solve it. This function uses a Runge-Kutta method to solve the equation. However, since you mentioned that you need to use the Relaxation Method, you can use a while loop to iterate and update the solution until it converges to the desired accuracy.

Here is a basic outline of the code:

% Define constants
A = ...;
B = ...;
C = ...;
D = ...;
f = @(N) log(N); % define the function f(N) here

% Define boundary conditions
B1 = ...;
B2 = ...;

% Define initial guess for solution
N = linspace(B1,B2,100); % initial guess is a linear interpolation between B1 and B2
tol = 1e-6; % tolerance for convergence
err = 1; % initialize error
while err > tol
% Update the solution using the relaxation method
N_new = ...; % update N using relaxation method
err = norm(N_new - N)/norm(N); % compute relative error
N = N_new; % update N
end

% Plot the solution
plot(linspace(-L,L,100),N)

I hope this helps you get started with solving your 1D 2nd-order nonlinear differential equation in MATLAB using the Relaxation Method. Keep in mind that this is just a basic outline and you may need to make adjustments based on your specific problem. Good luck!
 

1. What is a 1D 2nd-Order nonlinear differential equation?

A 1D 2nd-Order nonlinear differential equation is a mathematical equation that describes the relationship between a function, its first derivative, and its second derivative. It is called "nonlinear" because the function and its derivatives are not directly proportional to each other.

2. How is a 1D 2nd-Order nonlinear differential equation different from a linear differential equation?

In a linear differential equation, the function and its derivatives are directly proportional to each other. This means that the equation can be solved using simple algebraic methods. However, in a nonlinear differential equation, the relationship between the function and its derivatives is more complex and requires more advanced mathematical techniques to solve.

3. What is the purpose of solving a 1D 2nd-Order nonlinear differential equation in Matlab?

Matlab is a powerful computational tool that can solve complex mathematical problems, including 1D 2nd-Order nonlinear differential equations. The purpose of solving these equations in Matlab is to obtain a numerical solution that can be used to model and predict real-world phenomena in fields such as physics, engineering, and economics.

4. What are the steps for solving a 1D 2nd-Order nonlinear differential equation in Matlab?

The steps for solving a 1D 2nd-Order nonlinear differential equation in Matlab include defining the equation, setting initial conditions, selecting a numerical solver, specifying the time interval, and plotting the solution. It may also involve modifying the equation or using advanced techniques to improve the accuracy of the solution.

5. Can Matlab solve any type of 1D 2nd-Order nonlinear differential equation?

While Matlab is a powerful tool, it may not be able to solve every type of 1D 2nd-Order nonlinear differential equation. The complexity of the equation and the availability of suitable numerical solvers may affect the ability of Matlab to obtain a solution. In some cases, it may be necessary to use other software or manually solve the equation to obtain a solution.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
2
Replies
42
Views
15K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • Differential Equations
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
Back
Top