the code is not running showing collacation error...
1 次查看(过去 30 天)
显示 更早的评论
conediskexample()
function conediskexample
% Parameter values
A1 = 0.1;
A2 = 0.1;
A3 = 0.1;
A4 = 0.1;
A5 = 0.1;
A6 = 0.1;
M = 0.2;
Grt = 5;
Pr = 6.9;
R = 0.2;
Ec = 0.1;
Q = 0.1;
Rew = 12;
Red = -12;
eta = 0.06992681; % eta value used in ODEs
n = 1;
g1 = 1.0;
g2 = 0.5;
g3 = 0.9;
g4 = 0.9;
g5 = 0.9;
infinite = 20;
% Defining parameters
solinit = bvpinit(linspace(0, infinite, 500), [0 g1 g2 Rew g3 0 g4 1 g5]);
sol = bvp4c(@bvp2D, @bc2D, solinit);
if isempty(sol)
error('The solver failed to find a solution.');
end
x = sol.x;
y = sol.y;
% Plotting of the velocity
figure(1)
plot(x, y(2,:), 'linewidth', 1)
hold on
xlabel('\eta', 'fontweight', 'bold', 'fontsize', 16)
ylabel('f^{\prime}(\eta)', 'fontweight', 'bold', 'fontsize', 16)
hold off
% Plotting of theta
figure(2)
plot(x, y(4,:), 'linewidth', 1)
hold on
xlabel('\eta ', 'fontweight', 'bold', 'fontsize', 16)
ylabel('\theta(\eta) ', 'fontweight', 'bold', 'fontsize', 16)
hold off
% Plotting of phi
figure(3)
plot(x, y(6,:), 'linewidth', 1)
hold on
xlabel('\eta', 'fontweight', 'bold', 'fontsize', 16)
ylabel('\phi(\eta)', 'fontweight', 'bold', 'fontsize', 16)
hold off
% Residual of the boundary conditions
function res = bc2D(y0, yinf)
res = [y0(1); yinf(1);y0(4); yinf(4); y0(5) - Rew; yinf(5) - Red;y0(7) - 1; yinf(7)];
end
% System of First Order ODEs
function dydx = bvp2D(~, y)
yy1 = -(1+eta^2)*((10*A1*eta+A2*eta*y(1)-A2*y(4))*y(3))-3*(2*A1+7*A1*eta^2+A2*(2*eta^2+1)*y(1)-A2*eta*y(4))*y(2)-2*A2*y(5)*y(6)-3*(A1+A2*y(1))*y(4)+A3*M*y(2)-A4*Grt*y(8)/(A1*(1+eta^2)^2);
yy2 = eta*y(2);
yy3 = -3*A1*eta*y(6)-A2*(eta*y(1)-y(4))*y(6)+A3*M*y(5)/(A1*(eta^2+1));
yy4 = (A5+4/3*R)*((eta*(2*n-1))*y(8)+n^2*y(7))-A3*Pr*M*Ec*(y(1)^2+y(5)^2)-Pr*Q*y(7)+A6*Pr*(y(4)*y(8)+n*y(1)*y(7)-eta*y(1)*y(8))/(A5+4/3*R)*(1+eta^2);
dydx = [y(2); y(3); yy1; yy2; y(6); yy3; y(8); yy4];
end
end
please help to execute the above code..thanks in advance
1 个评论
Torsten
2024-9-9
You supply initial guesses for 9 unknown functions, but you supply spatial derivatives and boundary conditions for only 8 unknown functions.
回答(1 个)
Sandeep Mishra
2024-9-16
Hi Uma,
While running the code snippet in MATLAB R2024a, I encountered a similar error.
It can be observed that you are attempting to solve a boundary value problem using the 'bvp4c' function.
Upon inspecting the 'odefun' (bvp2D) and 'bcfun' (bc2D) functions, I noticed that they return a vector of size 8, indicating that the system involves 8 differential equations.
However, the 'solinit' variable, created using the 'bvpinit' function, defines a 500x9 vector, which means initial guess values are being provided for 9 variables.
This discrepancy leads to a dimension mismatch, causing the error while using ‘bvp4c’ function.
You can refer to the example code of second order system in the following MATLAB documentation:
To address this, you can either modify the 'solinit' variable to provide initial guess values for only 8 variables or update the 'odefun' and 'bcfun' functions to return a vector of size 9.
Following is a workaround where the 'solinit' is adjusted to contain 8 guess values by removing the ‘g5’ variable:
solinit = bvpinit(linspace(0, infinite, 500), [0 g1 g2 Rew g3 0 g4]);
sol = bvp4c(@bvp2D, @bc2D, solinit);
Please refer to the following documentation for more information.
- ‘bvp4c’ function: https://www.mathworks.com/help/releases/R2024a/matlab/ref/bvp4c.html
- ‘bvpinit’ function: https://www.mathworks.com/help/releases/R2024a/matlab/ref/bvpinit.html
I hope this helps.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!