dsolve problem got error
3 次查看(过去 30 天)
显示 更早的评论
eqn = diff(theta,2) == 1- theta^2/2 %Taylor approx of cos(theta) thetaSol = dsolve(eqn,cond) %theta_0 and diff(theta) is zero. I want to get function of theta, but solution got error. How can I get answer of theta, when diff(theta,2) == 1- theta^2/2?
2 个评论
Dyuman Joshi
2023-11-7
编辑:Dyuman Joshi
2023-11-7
eqn = diff(theta,2) == 1- theta^2/2
Differentiation of theta with respect to what? which variable?
回答(2 个)
nick
2023-11-16
Hi 지웅 장,
I understand that you are facing an issue with obtaining solution of the differential equation for the mentioned equation using 'dsolve'.
diff(theta,2) == 1- theta^2/2
'diff(theta,2)' computes the 2nd derivative of theta with respect to the symbolic scalar variable determined by symvar, which is 0. This leads to the input parameter to 'dsolve' function being, '0 == 1 - theta^2/2' , which is not a differential equation.
In any differential equation you need one or more dependent variable, 'theta' in this case, and an independent variable. You need to mention an independent variable to evaluate the differential equation by 'dsolve'. You may refer the following link to learn more about solving differential equation with 'dsolve' :
Hope it helps,
Regards,
Neelanshu Garg
0 个评论
Sam Chak
2023-11-16
Hi @지웅 장
If dsolve() cannot return an analytical solution, then use ode45 solver to obtain a numerical solution.
However, WolframAlpha is able to return an analytical solution in terms of Weierstrass elliptic function, ℘.

% syms y(t)
% eqn = diff(y,t,2) == 1 - (y^2)/2;
% Dy = diff(y,t);
% cond = [y(0)==0, Dy(0)==1];
% ySol(t) = dsolve(eqn, cond, 'ExpansionPoint', 0)
tspan = linspace(0, 10, 1001);
y0 = [0; 1];
[t, y] = ode45(@odefcn, tspan, y0);
plot(y(:,1), y(:,2)), grid on
xlabel('y_{1}'), ylabel('y_{2}')
function dydt = odefcn(t, y)
dydt = zeros(2, 1);
dydt(1) = y(2);
dydt(2) = 1 - (y(1)^2)/2;
end
1 个评论
Sam Chak
2023-11-16
Hi @지웅 장
If the original cosine function is used, an analytical solution can be found, where
is the Jacobi amplitude function. This solution is commonly encountered in the study of undamped pendulum responses within highly advanced pure mathematics topics, rather than in superficially simple engineering mathematics.
syms y(t)
eqn = diff(y,t,2) == cos(y);
Dy = diff(y,t);
ySol(t) = dsolve(eqn)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Equation Solving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

