dsolve problem got error

조회 수: 3 (최근 30일)
지웅 장
지웅 장 2023년 11월 7일
댓글: Sam Chak 2023년 11월 16일
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
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?
R
R 2023년 11월 14일
Can you also share the error you are encountering?

댓글을 달려면 로그인하십시오.

답변 (2개)

nick
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

Sam Chak
Sam Chak 2023년 11월 16일
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
Sam Chak 2023년 11월 16일
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)
ySol(t) = 

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Equation Solving에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by