Solve and Vpasolve can't find solutions
4 views (last 30 days)
Show older comments
Hello
I am trying to solve this system of equations for my class. It is just 4 simple equations that I have already known the solutions. but when I tried to solve it using vpasolve and solve function it returned no solutions. So I am curious on what steps that I did wrong.
Thank you in advance
syms t real
v = 1/2*(2*10^3)*(0.5*cos(t))^2 - 0.75*9.81*20*cos(t)
dv = diff(v,1)
d2v = diff(dv,1)
eqn1 = dv == 0
eqn2 = d2v >= 0;
eqn3 = t < pi
eqn4 = t > 0
eqn = [eqn1,eqn2,eqn3,eqn4]
sol = solve(eqn,t)
This is the graph I plotted on Matlab for eqn1(blue) and 2(orange). There are several points that can be the solutions (blue = 0 and orange >0).
0 Comments
Accepted Answer
Steven Lord
on 28 Oct 2024
I am trying to solve this system of equations for my class.
No, you have a system of inequalities and equations. Let's try solving the one equation in one unknown first.
syms t real
v = 1/2*(2*10^3)*(0.5*cos(t))^2 - 0.75*9.81*20*cos(t)
dv = diff(v,1)
d2v = diff(dv,1)
sol = solve(dv == 0, t)
Now check if it satisifies your inequality on d2v.
check1 = subs(d2v, t, sol)
positiveSecondDerivative = isAlways(check1 >= 0)
Now the solutions that satisfy your equation and your first unknown:
solutions = sol(positiveSecondDerivative)
Which solutions satisfy your constraints on t?
inInterval0pi = isAlways(solutions > 0) & isAlways(solutions < pi)
realsolutions = solutions(inInterval0pi)
Let's check.
subs(dv, t, realsolutions)
subs(d2v, t, realsolutions)
isAlways(realsolutions > 0)
isAlways(realsolutions < pi)
0 Comments
More Answers (1)
Shivam Gothi
on 29 Oct 2024
As per my understanding, you are trying to find the set of solutions that satisfies the four set of equations specified by you.
From the graph attached by you, it is clearly seen that there are many solutions that satisfies the equations. For an example,
t = 1.2720733281966199317376699591669
Satisfies all the equations, but still it is not shown by the function “vpasolve”.
refer to the documentation for “vpasolve”:
It seems that the number of equations should be equal to the number of symbolic variables. In your case, you are using only one symbolic variable “t” and number of equations are equal to 4. As per my understanding, you should pass only one equation in the “vpasolve” function.
I found a workaround to solve the set of equations mentioned by you. I have found it to be working and attaching it at the end of this answer for your reference. (Note: the curve for the equation (dv=0) is plotted in "blue" and equation (d2v=0) is plotted in "red".
The explanation of the code is given below:
Divide the time interval into smaller intervals. For each interval, first solve the equation “eqn1” and find the point (values of “t”) that satisfies it. The solution should lie between the interval specified by “eqn3” and “eqn4”. As a next step, find the value of “d2v” variable for the evaluated solution. If the value of “d2v” is greater than 0, that means we have found one of the solution of equations. Therefore, store them in a vector. Keep on repeating this procedure for all the time intervals.
In the code, I have defined the time range as : 0 < t < 6, and also plotted the equations "dv=0" and "d2v=0" for your reference.
clc;
clear;
syms t real
v = 1/2*(2*10^3)*(0.5*cos(t))^2 - 0.75*9.81*20*cos(t);
dv = diff(v,1);
d2v = diff(dv,1);
eqn1 = dv == 0;
eqn2 = d2v >= 0;
eqn3 = t < pi;
eqn4 = t > 0;
%Instead of making use of Eqn3 and Eqn4, I have defined the
%"starting_value" and "ending_value". Interval_length variable is defined
%to tell vpasolve() function to look for a solution in the prescribed time
%interval. You can narrow down the interval to find more solutions.
interval_length=1;
starting_value=0;
ending_value=6;
solution_vector=[]; % Create an empty solution vector that will hold all the possible solutions of the
% four equations.
for time=-5:0.01:5
plot(time,subs(dv,t,time),'b.');
hold on;
end
for time=-5:0.01:5
plot(time,subs(d2v,t,time),'r.');
hold on;
end
while (starting_value<ending_value)
sol = vpasolve(eqn1,t,[starting_value,(starting_value+interval_length)]);
value_of_d2v = subs(d2v,t,sol);
if(value_of_d2v>=0)
solution_vector(end+1)=sol;
end
starting_value=starting_value+interval_length;
end
disp("The solution (values of t) which satisfies all the equations are given below:");
disp(solution_vector);
Additionally, please refer to the below documentation to understand the functions used in the code:
I hope it helps !
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!