Why do I receive the error while running the code?

조회 수: 2 (최근 30일)
MINATI PATRA
MINATI PATRA 2023년 12월 10일
답변: Walter Roberson 2023년 12월 10일
coupled_dtm_bvp_solver()
Warning: Unable to find symbolic solution.
Incorrect number or types of inputs or outputs for function matlabFunction.

Error in solution>coupled_dtm_bvp_solver (line 8)
u_sol = matlabFunction(ode1, 'Vars', {'x', 'u', 'v', 'w'}); v_sol = matlabFunction(ode2, 'Vars', {'x', 'u', 'v', 'w'}); w_sol = matlabFunction(ode3, 'Vars', {'x', 'u', 'v', 'w'});
function coupled_dtm_bvp_solver
syms x u(x) v(x) w(x)
eq1 = diff(u, x, x, x) - u^2 + v - sin(w*x) == 0; eq2 = diff(v, x, x, x) - u*v + w == 0; eq3 = diff(w, x, x, x) - u*w + v^2 == 0;
x0 = 0; xn = 1; u0 = 0; vn = 1; w0 = 0;
[ode1, ode2, ode3] = dsolve(eq1, eq2, eq3, 'u(x0) == u0', 'u(xn) == vn', 'w(x0) == w0', 'Dw(xn) == 0');
u_sol = matlabFunction(ode1, 'Vars', {'x', 'u', 'v', 'w'}); v_sol = matlabFunction(ode2, 'Vars', {'x', 'u', 'v', 'w'}); w_sol = matlabFunction(ode3, 'Vars', {'x', 'u', 'v', 'w'});
x_values = linspace(x0, xn, 100);
u_values = zeros(size(x_values)); v_values = zeros(size(x_values)); w_values = zeros(size(x_values));
for i = 2:length(x_values)
delta_x = x_values(i) - x_values(i-1);
u_values(i) = u_sol(x_values(i-1), u_values(i-1), v_values(i-1), w_values(i-1)) * delta_x + u_values(i-1);
v_values(i) = v_sol(x_values(i-1), u_values(i-1), v_values(i-1), w_values(i-1)) * delta_x + v_values(i-1);
w_values(i) = w_sol(x_values(i-1), u_values(i-1), v_values(i-1), w_values(i-1)) * delta_x + w_values(i-1);
end
figure(1);subplot(3,1,1);plot(x_values, u_values);title('Solution for u(x)');
subplot(3,1,2);plot(x_values, v_values);title('Solution for v(x)');
subplot(3,1,3);plot(x_values, w_values);title('Solution for w(x)');
xlabel('x');
end
  댓글 수: 3
Walter Roberson
Walter Roberson 2023년 12월 10일
Although it is no longer documented, instead of passing in a vector of symbolic equations, and a vector of symbolic initial conditions (total: two parameters), dsolve permits passing equations and initial conditions as multiple (scalar) parameters.
So you can have a single non-scalar parameter of equations, or you can have multiple scalar parameters of equations.
Also, although it is no longer documented, instead of passing symbolic initial conditions, it is still permitted to pass in character vectors of initial conditions, using the syntax 'VARIABLE(LOCATION)=VALUE' or using the syntax 'VARIABLE(LOCATION)==VALUE'.
It works for simple variables -- so for example the 'u(x0)==u0' is fine. However I am not certain at the moment if it is able to recognize D expressions -- historically it was able to do so.
These syntaxes are no longer documented or recommended, but they are not wrong.
MINATI PATRA
MINATI PATRA 2023년 12월 10일
Dw = dw/dx;
w(xn)==0 is the boundary condition

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

채택된 답변

Walter Roberson
Walter Roberson 2023년 12월 10일
[ode1, ode2, ode3] = dsolve(eq1, eq2, eq3, 'u(x0) == u0', 'u(xn) == vn', 'w(x0) == w0', 'Dw(xn) == 0');
MATLAB is not able to solve two-point boundaries on a single function. u(x0)==u0 by itself is fine, and u(xn)==vn by itself is fine, but you cannot set both of them.
dsolve() with an initial condition works by solving the function without conditions, and then substituting in the location of the condition , and then solving for the value of the appropriate constant of integration that would lead to the given initial value. After a successful solution for the initial condition, there are no remaining constants of integration at that level, so there is no constant to solve for to try to pin down any other initial condition for the same level of derivative.
Because of that boundary value issue, the above dsolve() cannot possibly succeed.
... that said, those equations are not ones that MATLAB can find symbolic solutions for, even without the initial conditions.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Equation Solving에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by