How do I use relational and logical operators to find specific function values?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I'm suppose to determine a) the time when the function h(t) exceeds the value 15, b) the time when the function h(t) exceeds the value 15 while the function v(t) does not exceed 36. I have to use relational och logical operators to determine these values. Is there any way to do this without creating a vector for the values between 0 and t_hit since then I have to set my own interval and therefore won't get a very precise answer? Is there a better approach to this problem?
MATLAB code:
close all; clear all; clc;
A = pi/6; v0 = 40; g = 9.81;
t_hit = (2*(v0/g)*sin(A));
t = 0:0.001:t_hit;
h = @(t) v0*t*sin(A)-0.5*g*t.^2;
v = @(t) sqrt(v0.^2-2*v0*g*t*sin(A)+g.^2*t.^2);
H=h(0:0.001:t_hit);
V=v(0:0.001:t_hit);
z1 = (H>15);
z2 = (H>15 & V<36);
T1=[]; T2=[];
for i=1:4078
if z1(i)==1
T1=[T1, t(i)];
end
if z2(i)==1
T2=[T2, t(i)];
end
end
2 Kommentare
Juliano Souza dos Passos
am 18 Okt. 2018
Bearbeitet: Juliano Souza dos Passos
am 18 Okt. 2018
I'm not sure if I got your question. I'll try to answer based on points a and b. A) Time t for h > 15
coln = find(z1);
Time_Exceeds15 = t(coln(1)); %Time which h > 15 for the first time
For question B) Time interval for h > 15 and v < 36
T_interval = t(z2);
H_interval = H(z2);
V_interval = V(z2);
Please use your code, but you can exclude the structure 'for'.
Akzeptierte Antwort
Luna
am 18 Okt. 2018
You can do it without creating z1 and z2. But you can't do it without creating H and V. You have to create your functions outputs.
try below instead of for loop:
dt = 0.001; % Sample Time
time1 = find(H>15)*dt;
time2 = find((H>15 & V<36))*dt;
1 Kommentar
Guillaume
am 18 Okt. 2018
Well, it could be done analytically without creating H and V, using fzero or similar, but since this homeworks specifically asks to use relational operators I would think that discretizing the functions is indeed what is expected.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Bartlett finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!