System of inequalities using logical operators
Show older comments
Hello Mathworks Community,
My name is John Dimopoulos and I'm an undergraduate from the department of Aeronautical Engineering in Greece (sorry for my English, though). I have a question. I have 2 functions:
h(t) = 20*t - 4.905*t^2
u(t) = sqrt(1600 - 392.4*t + 96.2361*t^2)
How can I find the range that the variable "t" takes if I say for example that h(t) < 15 and u(t) < 36 (maybe using the logical &)?
Also, how can I find the value of variable "t" when h(t) is marginally smaller than 15?
For the above I'd like to use logical operations ( & , |)
Yours sincerely,
John Dimopoulos
5 Comments
John Dimopoulos
on 2 Jan 2018
Guillaume
on 2 Jan 2018
"How can I find the range that the variable "t" takes"
"I'd like to solve my problem using logical operators"
These two statements are incompatible. Why do you even think that logical operators would be useful in solving that problem? You've been shown several to solve your problem. These are the right tools to use.
"Also, there's no need for graphs.". Maybe not, but they're useful. In particular, if you'd looked at the graph of your functions, you'd have realised immediately that there is no solution for h(t)<15 and u(t)<36
Image Analyst
on 2 Jan 2018
Well part of the whole problem is that the problem is ambiguously stated. If you took my solution and figured out
hRoots = roots([-4.905, 20, -15])
uRoots = roots([96.2361, -392.4, 1600-36^2])
Then you'd see the ranges of t for each curve (checking curve u, and checking curve h):
hRoots =
3.0868
0.99072
uRoots =
3.0375
1.04
Using the plot I gave you

helps you to know that the range for h goes from -inf to 0.99072, and again from 3.0868 to +inf, and NOT from 0.99072 to 3.0868 like what you might think if you weren't looking at a plot. So the situation we have is
h(t) < 15 in two ranges: from [-inf, .99072] and [3.0868, inf]
u(t) < 36 in one range: from [1.04, 3.0375]
Now, those two ranges of t DO NOT overlap so when you say "I find the range that the variable "t" takes" do you mean the two separate sets of t-ranges I gave above, OR do you mean one set of three disconnected t-ranges?
OR when you say "the range that the variable "t" takes if I say for example that h(t) < 15 and u(t) < 36" do you mean the range of t where h<15 AND u<36 both simultaneously? In that case, as Walter and I've shown, there is no range of t satisfying both conditions simultaneously, so there is no solution.
So which is it???
Please remove the ambiguity and clarify your wording.
John Dimopoulos
on 3 Jan 2018
Edited: John Dimopoulos
on 3 Jan 2018
Image Analyst
on 3 Jan 2018
Of course it can. You can just use roots() like I showed you and check each of the three ranges (i.e. ANY point within that range is good enough) with if statements to see if any of them are true.
meetsCriteria = false;
uRoots = sort(uRoots, 'Ascend');
hRoots = sort(hRoots, 'Ascend');
t1 = min([uRoots(1), hRoots(1)]) - 1;
if uRoots(t1) < 36 && hRoots(t1) < 15
meetsCriteria = true;
end
and so on for picking t2 and t3 in the other ranges. I'm sure you can figure it out. No plotting is necessary, though it helps you to visualize.
Answers (4)
Image Analyst
on 1 Jan 2018
Consider writing like this:
15 = 20*t - 4.905*t^2
36^2 = 1600 - 392.4*t + 96.2361*t^2
Now, look at those equations and see how you can rearrange them to get the coefficients to pass into the roots() function.
You might also throw up a plot of them to make sure you're picking the right places:
t = linspace(0, 4, 1000);
h = 20*t - 4.905*t.^2;
u = sqrt(1600 - 392.4*t + 96.2361*t.^2)
plot(t, h, 'b-', 'LineWidth', 2);
hold on;
plot(t, u, 'r-', 'LineWidth', 2);
grid on;
% Put line across at 15
line(xlim, [15,15], 'color', 'm');
% Put line across at 36
line(xlim, [36,36], 'color', 'm');
legend('h', 'u', '15', '36', 'Location', 'east');
Star Strider
on 2 Jan 2018
Edited: Star Strider
on 2 Jan 2018
This turned out to be something of a challenge. I used fsolve to determine the points of equality. I will let you interpret the results.
The Code:
h = @(t) 20*t - 4.905*t.^2;
u = @(t) sqrt(1600 - 392.4*t + 96.2361*t.^2);
hu = @(t) [h(t) - 15; u(t) - 36];
[td{1}, fval] = fsolve(hu, rand(2,1));
[td{2}, fval] = fsolve(hu, rand(2,1)*100);
M = [td{1}(1), h(td{1}(1)); td{1}(2), u(td{1}(2)); td{2}(1), h(td{2}(1)); td{2}(2), u(td{2}(2))];
tv = linspace(0, 5);
figure(1)
plot(tv, h(tv), tv, u(tv))
hold on
plot(td{1}, h(td{1}), 'pg', 'MarkerSize',10, 'MarkerFaceColor','g')
plot(td{1}, u(td{1}), 'pg', 'MarkerSize',10, 'MarkerFaceColor','g')
plot(td{2}, h(td{2}), 'pg', 'MarkerSize',10, 'MarkerFaceColor','g')
plot(td{2}, u(td{2}), 'pg', 'MarkerSize',10, 'MarkerFaceColor','g')
hold off
text(M(1,1), M(1,2), sprintf('h(%.2f) = %.2f', M(1,1), M(1,2)))
text(M(2,1), M(2,2), sprintf('u(%.2f) = %.2f', M(2,1), M(2,2)))
text(M(3,1), M(3,2), sprintf('h(%.2f) = %.2f', M(3,1), M(3,2)))
text(M(4,1), M(4,2), sprintf('u(%.2f) = %.2f', M(4,1), M(4,2)))

EDIT — Added plot image.
Walter Roberson
on 2 Jan 2018
Edited: Walter Roberson
on 2 Jan 2018
syms t
h(t) = 20*t - 4.905*t^2;
u(t) = sqrt(1600 - 392.4*t + 96.2361*t^2);
solh = solve(h(t)==15);
solu = solve(u(t)==36);
Now, h is quadratic and points downwards, so it is less than 15 only outside the range solh(1) to solh(2), approximately 0.99071860040979604048152909881089 to 3.0867533669704282204766768135235 (that is, inside that range is all > 15)
If you remove the sqrt() from u then it is quadratic and points upwards, so it is less than 36 only inside the range solu(1) to solu(2), approximately 1.0399634076317316246961194857351 to 3.0375085597484929194928881689355.
Now if you examine those values, you will see that solh entirely contains solu -- so in the range where u is less than 36, h is exclusively more than 15. There is no solution to the question.
5 Comments
Walter Roberson
on 3 Jan 2018
Edited: Walter Roberson
on 8 Jan 2018
"I mean the range of t where h<15 AND u<36 both simultaneously.Matlab can't just tell me that there ISN'T a range of t that satisfies the two above conditions without using graphs ??"
syms t
h(t) = 20*t - 4.905*t^2;
u(t) = sqrt(1600 - 392.4*t + 96.2361*t^2);
solve(h(t)<15 & u(t)<36)
ans =
Empty sym: 0-by-1
There, it just told you there is no t satisfying those conditions, without using any graph. But if you want to know why there is no solution, then graphs certainly are handy.
Note: when you use inequalities, if there is a range of solutions, MATLAB might only return a single point satisfying the inequalities. See https://www.mathworks.com/matlabcentral/answers/356969-solving-absolute-value-inequality#answer_281887 for my description of which value will be returned out of the interval.
John BG
on 8 Jan 2018
Hi Walter
actually, there is a brief overlap, please check my answer, it's not a single point, but very short pulses.
Image Analyst
on 8 Jan 2018
We don't believe there is. I think the overlap area you're showing is where neither is true, not both are true. Prove us wrong by providing an actual t value, like t=1.02 or t=3.05 or whatever works so we can plug it in the equations and see:
t = 1.02
t = 3.05
% Need h < 15 and u < 36.
h = 20*t - 4.905*t.^2
u = sqrt(1600 - 392.4*t + 96.2361*t.^2)
What t value are you using that has h<15 and u<36 both at the same time?
John Dimopoulos
on 8 Jan 2018
Mr Dimopoulos, Image Analyst, Walter Roberson
if
a=sqrt(b)
then is it also true that
-a=sqrt(b)
this means that your equations
h < 15 and u < 36
h = 20*t - 4.905*t.^2
u = sqrt(1600 - 392.4*t + 96.2361*t.^2)
same as
20*t - 4.905*t.^2- 15 < 0
sqrt(1600 - 392.4*t + 96.2361*t.^2) - 36 < 0
should be completed with:
20*t - 4.905*t.^2- 15 < 0
-sqrt(1600 - 392.4*t + 96.2361*t.^2) + 36 > 0
the 1st set of equations, as used by Image Analyst and Walter Roberson, are
h-h0<0
u-u0<0
So, let the thresholds be included in equations
h0=15;
eqn1=20*t - 4.905*t^2-h0
u0=36;
eqn2=sqrt(1600 - 392.4*t + 96.2361*t^2)-u0
h = 20*t - 4.905*t.^2-h0;
u = (1600 - 392.4*t + 96.2361*t.^2).^.5-u0;
figure(1);plot(t, h, 'b-', 'LineWidth', 2);hold on;
figure(1);plot(t, u, 'r-', 'LineWidth', 2);grid on;
This is the 1st graph of my question.
As pointed out by Image Analyst and Water Roberson there's no overlap among the intervals where the blue, h-h0 trace < 0 and red, u-u0 trace < 0.
However, the following set of equations that have not been considered:
h = 20*t - 4.905*t.^2-h0;
u = -(1600 - 392.4*t + 96.2361*t.^2).^.5+u0;
figure(2);plot(t, h, 'b-', 'LineWidth', 2);hold on;
figure(2);plot(t, u, 'r-', 'LineWidth', 2);grid on;
This is like the 1st graph of my answer but upside down.
Now looking for
h-h0<0
-u+u0>0
intervals where the blue, h-h0 trace < 0 and red, -u+u0 trace > 0.
It turns that there are 2 short overlap intervals, easily spotted with
figure(3);plot(t, sign(h), 'b-', 'LineWidth', 2);hold on;
figure(3);plot(t, sign(u), 'r-', 'LineWidth', 2);grid on;
The overlap intervals being
w=sign(u)+sign(h);
plot(t,w,'r-', 'LineWidth', 2);grid on
The sought t overlap values in t_trigger
[row,col,v]=find(w>1);
t_trigger=t(col)
As shown in my answer below.
square roots always carry with them a + - that many times is ignored.
Hi Mr Dimopoulos
1.
The Intersections can be found the following way:
For 1st function
.
syms t
h0=15;
eqn1=20*t - 4.905*t^2-h0
[t1,params,conds]=solve(eqn1,t,'ReturnConditions',true)
t1 =
2000/981 - (10*10^(1/2)*1057^(1/2))/981
(10*10^(1/2)*1057^(1/2))/981 + 2000/981
params =
Empty sym: 1-by-0
conds =
TRUE
TRUE
double(t1)
=
0.990718600409796
3.086753366970428
.
For 2nd function
.
u0=36;
eqn2=sqrt(1600 - 392.4*t + 96.2361*t^2)-u0
[t2,params,conds]=solve(eqn2,t,'ReturnConditions',true)
t2 =
11505289673048064/5643344584630075 - (16777216*2^(1/2)*507901012616706897^(1/2))/16930033753890225
(16777216*2^(1/2)*507901012616706897^(1/2))/16930033753890225 + 11505289673048064/5643344584630075
params =
Empty sym: 1-by-0
conds =
TRUE
TRUE
>> double(t2)
ans =
1.039963407631732
3.037508559748493
.
2.-
While the crossings themselves are of interest, the point of the question is to find the time values satisfying BOTH functions, All functions defined in the question.
To such purpose let's focus on when both signals do meet the AND you mention in your question
.
The following are the functions themselves
.
h = 20*t - 4.905*t.^2-h0;
u = (1600 - 392.4*t + 96.2361*t.^2).^.5-u0;
plot(t, h, 'b-', 'LineWidth', 2);hold on;
plot(t, u, 'r-', 'LineWidth', 2);grid on;
.

.
And the following the AND condition applied to both functions:
.
plot(t, sign(h), 'b-', 'LineWidth', 2);hold on;
plot(t, sign(u), 'r-', 'LineWidth', 2);grid on;
.

.
which in turn is
.
w=sign(u)+sign(h);
plot(t,w,'r-', 'LineWidth', 2);grid on
.

.
3.- The t values that satisfy the requirements of your question can be found the following way:
[row,col,v]=find(w>1);
t_trigger=t(col)
.
Mr Dimopoulos
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance for time and attention
John BG
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!