data not generating and error in plotting
2 ビュー (過去 30 日間)
古いコメントを表示
% Define initial parameters
lambda_init = 2;
kappa_init = 1;
theta_k_init = pi/10;
R_init = 7;
rout = 3;
% Define c
c = sqrt(4 - (rout/R_init)^2);
% Define the function for the differential equations
f = @(r, y) [y(2); ((-1*(lambda_init+1)*(r*y(2)+y(1)))+(1/r)*((kappa_init*r^2*cos(theta_k_init)-(lambda_init+1))*y(1))-(kappa_init*r*y(3)*sin(theta_k_init))+(-16*lambda_init*r^2)/(c^4*R_init^2)); y(4); ((-1*(r*y(4)+y(3)))+(1/r)*((kappa_init*r^2*cos(theta_k_init)-1)*y(3))+(kappa_init*r*y(1)*sin(theta_k_init)))];
% Solve the differential equations using ode45
r_span = linspace(0, rout, 100); % Define the range of r values
[~, sol] = ode45(f, r_span, [0, 0, 0, 0]);
% Extract solutions
dr_sol = sol(:,1);
dtheta_sol = sol(:,3);
% Plot the solutions
figure;
subplot(2,1,1);
plot(r_span, dr_sol, 'b-');
xlabel('r');
ylabel('dr(r)');
title('Solution of dr(r) vs r');
subplot(2,1,2);
plot(r_span, dtheta_sol, 'b-');
xlabel('r');
ylabel('dtheta(r)');
title('Solution of dtheta(r) vs r');
I am trying to solve the coupled differential eqns for d_r(r) vs r and d_theta(r) vs r for these parameter values and boundary conditions so that it is zero at both end d_r(0) = d_r(rout) = 0 and the same for d_theta. However, Not able to see the plot and data. please suggest me errors.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1706601/image.jpeg)
0 件のコメント
採用された回答
Torsten
2024 年 5 月 30 日
移動済み: Torsten
2024 年 5 月 30 日
And what is the "correct" result ?
According to your mathematical description, I get this:
% Define initial parameters
lambda_init = 1.2;
kappa_init = 1;
theta_k_init = pi/10;
R_init = 7;
rout = 3;
% Define c
c = sqrt(4 - (rout/R_init)^2);
% Initial guess for the solution
solinit = bvpinit(linspace(0.0001, rout, 100), [0, 0, 0, 0]);
% Solve the BVP
sol = bvp4c(@(r, y) odefun(r, y, lambda_init, kappa_init, theta_k_init, c, R_init), @bcfun, solinit);
% Extract solutions
r = linspace(0.0001, rout, 100);
y = deval(sol, r);
dr_sol = y(1,:);
dtheta_sol = y(3,:);
% Plot the solutions
figure;
subplot(2,1,1);
plot(r, dr_sol, 'b-');
xlabel('r');
ylabel('dr(r)');
title('Solution of dr(r) vs r');
subplot(2,1,2);
plot(r, dtheta_sol, 'b-');
xlabel('r');
ylabel('dtheta(r)');
title('Solution of dtheta(r) vs r');
% Define the function for the differential equations
function dydr = odefun(r, y, lambda_init, kappa_init, theta_k_init, c, R_init)
dydr = zeros(4,1);
dydr(1) = y(2);
dydr(2) = -((lambda_init+1)*y(2)+1/r*(kappa_init*r^2*cos(theta_k_init)-(lambda_init+1))*y(1)-kappa_init*r*y(3)*sin(theta_k_init)+16*lambda_init*r^2/(c^4*R_init^2))/(r*(lambda_init+1));
dydr(3) = y(4);
dydr(4) = -(y(4)+1/r*(kappa_init*r^2*cos(theta_k_init)-1)*y(3)+kappa_init*r*y(1)*sin(theta_k_init))/r;
end
% Boundary conditions
function res = bcfun(ya, yb)
res = [ya(1); ya(3); yb(1); yb(3)];
end
2 件のコメント
Torsten
2024 年 5 月 30 日
I changed
y = deval(sol, r);
to
y = deval(sol, dr_data(:,1));
to make your code work.
Fitting is bad - you'll have to work on it.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!