System of inequalities using logical operators

7 views (last 30 days)
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
Image Analyst
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.

Sign in to comment.

Answers (4)

Image Analyst
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
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
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
John BG
John BG on 16 Jan 2018
Edited: John BG on 16 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.

Sign in to comment.


John BG
John BG on 2 Jan 2018
Edited: John BG on 16 Jan 2018
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

Community Treasure Hunt

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

Start Hunting!