How do I use relational and logical operators to find specific function values?
이전 댓글 표시
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'.
Jakob
2018년 10월 18일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Bartlett에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!