How can i solve initial value ordinary differential equation using matlab ??

I want to solve four differtial equation and these are shown in picture. Here u,s,p,r are dependent variable and t is the independent variable. W and a are the constant (values are 154 and 44.5 degree). t is the independent variable and varies from 0 to 180 degree. initial condition are u0 = 0.10, so = 0.2025, p0 = 1.4706, r0 = 2.2449.

5 Comments

I tried the below given code:-
a = 44.5;
W = 154.236;
tspan = [0 180];
y0 = [0.10 0.237 rad2deg(1.4706) 2.2449];
[T,Y] = ode15s(@(t,y)S(t,y,a),tspan,y0);
plot(T,Y(:,4));
function f = S(t,W,a)
syms u(t) s(t) p(t) r(t)
eq01 = u*diff(s,t) + s*diff(u,t) == (sind(a)^3)/(4*((cosd(a)*cosd(t)).^2));
eq02 = (u.^2)*diff(s,t)+(2*s*u)*diff(u,t) == cosd(a)*(sind(a)^3)/(4*((cosd(a)*cosd(t)).^2));
eq03 = (u.^2*s)*(1+diff(p,t))*sind(p) == (2*r/W) - (sind(p).^2)*(sind(a)^3)/(4*((cosd(a)*cos(t)).^2));
eq04 = diff(r,t) == r*cotd(p);
f = [eq01;eq02,eq03;eq04];
end
It seems to me that u and s are vectors, since here implies computing their cross-products. What are they exactly?
That aside, to use the equations as you wrote them and then get executable code that can be used with the MATLAB ODE integrators, first use odeToVectorField and then matlabFunction on the vector field result. (Return both results so that you know what substitutions were made.)
Use the symmatrix function to create u and s, since the intent is apparently to create their cross-products. That then causes a problem, because while taking the derivative of the cross product is not a problem (regardless of their being either row or column vectors), equating the resulting vector to the RHS scalar is a problem.
imshow(imread('Picture2.jpg'))
syms a t
u = symmatrix('u(t)',[3 1])
u = 
s = symmatrix('s(t)',[1 3])
s = 
LHS1 = diff(cross(u,s))
LHS1 = 
RHS1 = sin(a)^3/(4*(1+cos(a)*cos(t))^2)
RHS1 = 
Eq1 = LHS1 == RHS1
Error using symbolic.mixin.symbolicmatrix/engineHelperWrapper
Dimensions do not match.

Error in == (line 556)
X = symbolic.mixin.symbolicmatrix.engineHelperWrapper('Dom::SymbolicMatrix::eqMATLAB', A, B);
This needs to be clarified.
What do you want to do?
.
They are not cross product. It is simply multiplication and d/dt denote the differtiation with respect to t. I attached a picture for the equation. here is u s are the two differtent variable.
Some obvious mixe and match unit : sin and cos take argument in radian not in degree

Sign in to comment.

 Accepted Answer

I change integration variables to v=u*s and w=u^2*s;
This should work (you need to sort out the discrepency of unit, speccially for t)
W = 154;
a = deg2rad(44.5);
u0 = 0.10;
s0 = 0.2025;
p0 = 1.4706;
r0 = 2.2449;
v0 = u0*s0;
w0 = u0^2*s0;
y0 = [v0;w0;p0;r0];
sol = ode45(@(t,y) odefun(t,y,a,W),[0 pi],y0);
t = sol.x;
y = sol.y;
v = y(1,:);
w = y(2,:);
p = y(3,:);
r = y(4,:);
u = w./v;
s = v./u;
tdeg = rad2deg(t)
tdeg = 1×13
0 7.9475 21.1057 35.2541 53.2541 71.2541 89.2541 107.2541 125.2541 143.2541 158.1571 171.0410 180.0000
figure
subplot(2,2,1); plot(tdeg, u); xlabel('tdeg'); ylabel('u')
subplot(2,2,2); plot(tdeg, s); xlabel('tdeg'); ylabel('s')
subplot(2,2,3); plot(tdeg, p); xlabel('tdeg'); ylabel('p')
subplot(2,2,4); plot(tdeg, r); xlabel('tdeg'); ylabel('r')
function dydt = odefun(t, y, a, W)
%v = y(1); % u*s
w = y(2); % u^2*s
p = y(3);
r = y(4);
sina = sin(a);
cosacost = cos(a).*cos(t);
c = sina^3./(4*(1+cosacost).^2);
dvdt = c;
dwdt = c.*cos(p);
dpdt = (2*r/W - c*sin(p).^2) ./ (w.*sin(p)) - 1;
drdt = t ./ tan(p);
dydt = [dvdt; dwdt; dpdt; drdt];
end

More Answers (0)

Products

Release

R2023a

Community Treasure Hunt

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

Start Hunting!