dsolve problem got error
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Dyuman Joshi
am 7 Nov. 2023
Bearbeitet: Dyuman Joshi
am 7 Nov. 2023
eqn = diff(theta,2) == 1- theta^2/2
Differentiation of theta with respect to what? which variable?
Antworten (2)
nick
am 16 Nov. 2023
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 Kommentare
Sam Chak
am 16 Nov. 2023
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 Kommentar
Sam Chak
am 16 Nov. 2023
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)
Siehe auch
Kategorien
Mehr zu Equation Solving finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

