How do I use relational and logical operators to find specific function values?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
Juliano Souza dos Passos
2018년 10월 18일
편집: Juliano Souza dos Passos
2018년 10월 18일
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'.
채택된 답변
Luna
2018년 10월 18일
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
Guillaume
2018년 10월 18일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Bartlett에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!