Solving an equation with derivatives in it.
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to solve an equation that has differentiation in it and getting some issues with it. Here's the code
clc
syms x(t) y(t)
eqn = y == 0.03*x^2; %Given equation of the path
v_y = diff(eqn) %Taking the time derivative of the equation, i.e dy/dt = 0.06x * dx/dt
pretty(v_y)
a_y = diff(v_y); %Taking another timer derivative dy^2/(dt^2 = 0.06*(dx/dt)^2 + 0.06*x*(dx^2/dt^2)
pretty(a_y)
x = -5; %Setting the value of x
equation_1 = 12^2 == (diff(x(t), t))^2 + (v_y)^2; %writing out the equation for velocity, i.e v^2 = v_x^2 + v_y^2
v_x = solve(equation_1,(diff(x(t), t))) %Solving the equation for v_x or dx/dt
The error reads:
Error using sym/subsindex (line 845)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be
symbolic variables, and function body must be sym expression.
Error in Untitled (line 13)
equation_1 = 12^2 == (diff(x(t), t))^2 + (v_y)^2;
0 commentaires
Réponses (1)
Walter Roberson
le 28 Jan 2020
Cx = -5; %Setting the value of x
Vequation_1 = 12^2 == (diff(x(t), t))^2 + (v_y)^2;
You assigned x a numeric value so x(t) is trying to access that scalar at a symbolic location.
Construct the equation first. subs() the numeric value afterwards if appropriate
2 commentaires
Walter Roberson
le 28 Jan 2020
v_x = dsolve(equation_1,(diff(x(t), t)))
v_x.x and v_x.y will then exist, and will turn out to have content similar to C1 and C2. That indicates that the equation is solved with x(t) and y(t) are each constants, with the exact constants dependent on the boundary conditions.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!