System of inequalities using logical operators

3 次查看(过去 30 天)
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 个评论
John Dimopoulos
John Dimopoulos 2018-1-3
编辑:John Dimopoulos 2018-1-3
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 ??
Image Analyst
Image Analyst 2018-1-3
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.

请先登录,再进行评论。

回答(4 个)

Image Analyst
Image Analyst 2018-1-1
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 2018-1-2
编辑:Star Strider 2018-1-2
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 2018-1-2
编辑:Walter Roberson 2018-1-2
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 个评论
John Dimopoulos
John Dimopoulos 2018-1-8
Mr.Robenson thank you very much for your answer.That's exactly what I needed.Now I understand what it is this 'empty sym' I got for answer.
John BG
John BG 2018-1-16
编辑:John BG 2018-1-16
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.

请先登录,再进行评论。


John BG
John BG 2018-1-2
编辑:John BG 2018-1-16
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

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by