Can some share command for plotting contour plot in MATLAB using BVP4C. I will be extremely grateful.

조회 수: 5 (최근 30일)
i want plot stream lines graph in matlab using bvp4v code. Can some share command for plotting contour plot in MATLAB using BVP4C. I will be extremely grateful.
  댓글 수: 1
Torsten
Torsten 2023년 12월 11일
Please share your code. bvp4c has one independent variable, not two. So I don't know how a contour plot (that needs two independent variables) comes into play here.

댓글을 달려면 로그인하십시오.

답변 (1개)

Drishti
Drishti 2024년 9월 23일
Hi Ali,
The ‘bvp4c’ function is utilized to solve boundary value problems - fourth order method. To achieve a contour plot using ‘bvp4c’ function, we need to first solve the required differential equations.
The solution obtained from ‘bvp4c’ function can be further utilized to get contour plots as ‘contour’ function works on matrix data.
You can refer to the following example to understand the working of ‘bvp4c’ function.
% Define the system of ODEs
function dydx = odefun(x, y)
dydx = [y(2); -y(1)];
end
% Define the boundary conditions
function res = bcfun(ya, yb)
res = [ya(1); yb(1) - 1];
end
% Initial guess for the solution
xmesh = linspace(0, 1, 10);
solinit = bvpinit(xmesh, [0, 1]);
% Solve the BVP
sol = bvp4c(@odefun, @bcfun, solinit);
Furthermore, you can utilize the below code snippet to extend the output value of ‘bvp4c’ function to get contour plots.
% Evaluate the solution on a finer mesh
x = linspace(0, 1, 100);
y = deval(sol, x);
% Create a meshgrid for contour plotting
[X, Y] = meshgrid(linspace(0, 1, 100), linspace(-1, 1, 100));
% Interpolate the solution to get a matrix for contour plot
Z = interp1(x, y(1, :), X);
% Plot the contour using the interpolated solution
figure;
contour(X, Y, Z, 20);
For further information, you can refer to the MATLAB Documentation of ‘bvp4c’ and ‘contour’ functions.
  1. 'bvp4c' function : https://www.mathworks.com/help/releases/R2024a/matlab/ref/bvp4c.html
  2. 'contour' function : https://www.mathworks.com/help/releases/R2024a/matlab/ref/contour.html
I hope this resolves your query.

카테고리

Help CenterFile Exchange에서 Boundary Value Problems에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by