Why do I receive the error while running the code?
Mostrar comentarios más antiguos
coupled_dtm_bvp_solver()
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 comentarios
Dyuman Joshi
el 10 de Dic. de 2023
And, Is Dw supposed to be dw/dx? Or is it a typo, and it's just w(xN)==0 ?
Walter Roberson
el 10 de Dic. de 2023
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
el 10 de Dic. de 2023
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!