Solving the system of ODEs and algebraic Equation
I am trying to solve the coupled ODE with dependent algebraic equation using RK4 method. I tried with my code below. I want to plot v,w,p,R,u_s and h_r v/s t. But I am getting error "Too many input arguments". I tried to figure out the problem for daya but could not able to do. Can anyone point my mistake ?? ny help will be much aappreciated.
clear
close all
a = deg2rad(45); m = 0.683; We = 277; Re = 75;
b = (-0.13*m.^3+0.263*m.^2 +0.039*m +0.330)/tan(a);
h = 0.001;
t = 0:h:pi ;
y = zeros(4,length(t));
qs = [];
y(:,1) = [0.0424; 0.0042; pi/2; 1.7440];
for i = 1:1
t = t(i,1);
syms q
x = b*cos(t)*sin(a).^2; x01 = 4*((1-cos(t).^2*cos(a)^2)); x02 = (b*sin(t)*sin(a)).^2;
q_j = -((x -(x01-x02).^0.5)./(x01/4));
d = (b.^2*sin(a).^2 + q.^2*(1-cos(t).^2*cos(a).^2) + 2*b*q*cos(t)*sin(a)^2).^0.5;
u_j = 2*(m-1)*(4*d.^2-1) + m;
F = int(q*u_j, q, 0, q_j);
G = int(q*u_j^3,q,0,q_j);
% F = matlabFunction(F1);
% G = matlabFunction(G);
syms u_s
eqs = (y(4,i)-q_j).*F.*sin(a).*u_s.^3 +…
(y(4,i).^2+2*y(4,i)*((pi*(y(1,i).^2./y(2,i))).^0.5)+(16/(sin(a)*3*q_j.^3*y(4,i)*Re))*((y(4,i)-q_j)*F*sin(a)).^2)*u_s.^2 -…
((y(4,i)-q_j)*F*sin(a)-((F.^3*sin(a).^3)/(9))*((1/q_j.^3)-(1/y(4,i).^3))+((y(4,i)-q_j)*F*sin(a))*(4/(q_j*sin(a))))*u_s-…
((y(4,i)-q_j)*F*sin(a))*((4*sin(a).^2*F.^3*(y(4,i).^5-q_j.^5))/(15*q_j.^7*y(4,i).^5*Re));
eqs = matlabFunction(eqs, ‘Vars’, u_s);
u_s = fsolve(eqs,0.50);
k1 = odesym(t(i,1),y(:,i),a,We,Re,F,u_s);
k2 = odesym(t(i,1)+h/2,y(:,i)+h*k1/2,a,We);
k3 = odesym(t(i,1)+h/2,y(:,i)+h*k2/2,a,We);
k4 = odesym(t(i,1)+h,y(:,i)+h*k3,a,We);
y(:,i+1) = y(:,i) + (1/6)*(k1+2*k2+2*k3+k4)*h;
end
function dydt = odesym(t,y,We,Re,F,u_s)
v = y(1); w = y(2); p = y(3); R = y(4);
% u_b = w./v; s_b = (v.^2)./w;
h_r = ((F(t).^(3./2))./(G(t).^0.5))./R;
F_v = ((((w./v)-u_s.*cos(p))./(((v.^2./w)./pi).^0.5))*((h_r.*R)./(sin(p).*Re)));
dvdt = u_s.*h_r.*R;
dwdt = u_s.^2.*h_r.*R.*cos(p) + F_v;
dpdt = (((2.*R./We)-(u_s.^2.*h_r.*R.*sin(p).^2))/(w.*sin(p)))-1;
drdt = R./tan(p);
dydt = [dvdt; dwdt; dpdt; drdt];
endI am trying to solve the coupled ODE with dependent algebraic equation using RK4 method. I tried with my code below. I want to plot v,w,p,R,u_s and h_r v/s t. But I am getting error "Too many input arguments". I tried to figure out the problem for daya but could not able to do. Can anyone point my mistake ?? ny help will be much aappreciated.
clear
close all
a = deg2rad(45); m = 0.683; We = 277; Re = 75;
b = (-0.13*m.^3+0.263*m.^2 +0.039*m +0.330)/tan(a);
h = 0.001;
t = 0:h:pi ;
y = zeros(4,length(t));
qs = [];
y(:,1) = [0.0424; 0.0042; pi/2; 1.7440];
for i = 1:1
t = t(i,1);
syms q
x = b*cos(t)*sin(a).^2; x01 = 4*((1-cos(t).^2*cos(a)^2)); x02 = (b*sin(t)*sin(a)).^2;
q_j = -((x -(x01-x02).^0.5)./(x01/4));
d = (b.^2*sin(a).^2 + q.^2*(1-cos(t).^2*cos(a).^2) + 2*b*q*cos(t)*sin(a)^2).^0.5;
u_j = 2*(m-1)*(4*d.^2-1) + m;
F = int(q*u_j, q, 0, q_j);
G = int(q*u_j^3,q,0,q_j);
% F = matlabFunction(F1);
% G = matlabFunction(G);
syms u_s
eqs = (y(4,i)-q_j).*F.*sin(a).*u_s.^3 +…
(y(4,i).^2+2*y(4,i)*((pi*(y(1,i).^2./y(2,i))).^0.5)+(16/(sin(a)*3*q_j.^3*y(4,i)*Re))*((y(4,i)-q_j)*F*sin(a)).^2)*u_s.^2 -…
((y(4,i)-q_j)*F*sin(a)-((F.^3*sin(a).^3)/(9))*((1/q_j.^3)-(1/y(4,i).^3))+((y(4,i)-q_j)*F*sin(a))*(4/(q_j*sin(a))))*u_s-…
((y(4,i)-q_j)*F*sin(a))*((4*sin(a).^2*F.^3*(y(4,i).^5-q_j.^5))/(15*q_j.^7*y(4,i).^5*Re));
eqs = matlabFunction(eqs, ‘Vars’, u_s);
u_s = fsolve(eqs,0.50);
k1 = odesym(t(i,1),y(:,i),a,We,Re,F,u_s);
k2 = odesym(t(i,1)+h/2,y(:,i)+h*k1/2,a,We);
k3 = odesym(t(i,1)+h/2,y(:,i)+h*k2/2,a,We);
k4 = odesym(t(i,1)+h,y(:,i)+h*k3,a,We);
y(:,i+1) = y(:,i) + (1/6)*(k1+2*k2+2*k3+k4)*h;
end
function dydt = odesym(t,y,We,Re,F,u_s)
v = y(1); w = y(2); p = y(3); R = y(4);
% u_b = w./v; s_b = (v.^2)./w;
h_r = ((F(t).^(3./2))./(G(t).^0.5))./R;
F_v = ((((w./v)-u_s.*cos(p))./(((v.^2./w)./pi).^0.5))*((h_r.*R)./(sin(p).*Re)));
dvdt = u_s.*h_r.*R;
dwdt = u_s.^2.*h_r.*R.*cos(p) + F_v;
dpdt = (((2.*R./We)-(u_s.^2.*h_r.*R.*sin(p).^2))/(w.*sin(p)))-1;
drdt = R./tan(p);
dydt = [dvdt; dwdt; dpdt; drdt];
end I am trying to solve the coupled ODE with dependent algebraic equation using RK4 method. I tried with my code below. I want to plot v,w,p,R,u_s and h_r v/s t. But I am getting error "Too many input arguments". I tried to figure out the problem for daya but could not able to do. Can anyone point my mistake ?? ny help will be much aappreciated.
clear
close all
a = deg2rad(45); m = 0.683; We = 277; Re = 75;
b = (-0.13*m.^3+0.263*m.^2 +0.039*m +0.330)/tan(a);
h = 0.001;
t = 0:h:pi ;
y = zeros(4,length(t));
qs = [];
y(:,1) = [0.0424; 0.0042; pi/2; 1.7440];
for i = 1:1
t = t(i,1);
syms q
x = b*cos(t)*sin(a).^2; x01 = 4*((1-cos(t).^2*cos(a)^2)); x02 = (b*sin(t)*sin(a)).^2;
q_j = -((x -(x01-x02).^0.5)./(x01/4));
d = (b.^2*sin(a).^2 + q.^2*(1-cos(t).^2*cos(a).^2) + 2*b*q*cos(t)*sin(a)^2).^0.5;
u_j = 2*(m-1)*(4*d.^2-1) + m;
F = int(q*u_j, q, 0, q_j);
G = int(q*u_j^3,q,0,q_j);
% F = matlabFunction(F1);
% G = matlabFunction(G);
syms u_s
eqs = (y(4,i)-q_j).*F.*sin(a).*u_s.^3 +…
(y(4,i).^2+2*y(4,i)*((pi*(y(1,i).^2./y(2,i))).^0.5)+(16/(sin(a)*3*q_j.^3*y(4,i)*Re))*((y(4,i)-q_j)*F*sin(a)).^2)*u_s.^2 -…
((y(4,i)-q_j)*F*sin(a)-((F.^3*sin(a).^3)/(9))*((1/q_j.^3)-(1/y(4,i).^3))+((y(4,i)-q_j)*F*sin(a))*(4/(q_j*sin(a))))*u_s-…
((y(4,i)-q_j)*F*sin(a))*((4*sin(a).^2*F.^3*(y(4,i).^5-q_j.^5))/(15*q_j.^7*y(4,i).^5*Re));
eqs = matlabFunction(eqs, ‘Vars’, u_s);
u_s = fsolve(eqs,0.50);
k1 = odesym(t(i,1),y(:,i),a,We,Re,F,u_s);
k2 = odesym(t(i,1)+h/2,y(:,i)+h*k1/2,a,We);
k3 = odesym(t(i,1)+h/2,y(:,i)+h*k2/2,a,We);
k4 = odesym(t(i,1)+h,y(:,i)+h*k3,a,We);
y(:,i+1) = y(:,i) + (1/6)*(k1+2*k2+2*k3+k4)*h;
end
function dydt = odesym(t,y,We,Re,F,u_s)
v = y(1); w = y(2); p = y(3); R = y(4);
% u_b = w./v; s_b = (v.^2)./w;
h_r = ((F(t).^(3./2))./(G(t).^0.5))./R;
F_v = ((((w./v)-u_s.*cos(p))./(((v.^2./w)./pi).^0.5))*((h_r.*R)./(sin(p).*Re)));
dvdt = u_s.*h_r.*R;
dwdt = u_s.^2.*h_r.*R.*cos(p) + F_v;
dpdt = (((2.*R./We)-(u_s.^2.*h_r.*R.*sin(p).^2))/(w.*sin(p)))-1;
drdt = R./tan(p);
dydt = [dvdt; dwdt; dpdt; drdt];
end ode MATLAB Answers — New Questions