フィルターのクリア

How can I find x values given a FOR command?

1 回表示 (過去 30 日間)
Michael Sabol
Michael Sabol 2020 年 4 月 18 日
回答済み: per isakson 2020 年 4 月 18 日
I need to find out what x values are created at certain intervals of t. t is in a matrix of 0:5:55;
clear;
close;
clc;
a = 40*(pi/180);
v = 1200;
g = 32.2;
k=[0,2e-6,10e-6,20e-6];
k=0;
dt=.5;
t = 0:dt:55
vx = v*cos(a)
vy = v*sin(a)
x = zeros(length(t),4);
y = zeros(length(t),4);
x(1,1)=0;
y(1,1)=0;
vx(1,1)=vx;
vy(1,1)=vy;
for j=2:length (t)
x(j,1) = x(j-1,1)+vx(j-1,1)*dt-.5*k*v(j-1,1).^2*cos(a)*dt.^2
y(j,1) = y(j-1,1)+vy(j-1,1)*dt-5*k*v(j-1,1).^2*sin(a)*dt^2-0.5*g*dt.^2
vx(j,1) = vx(j-1,1)-k*v(j-1,1).^2*cos(a)*dt
vy(j,1) = vy(j-1,1)-k*v(j-1,1).^2*sin(a)*dt-g*dt
a=atan(vy(j,1)./vx(j,1))
v(j,1)=vx(j,1).^2+vy(j,1).^2
end
find (x) = 0:5:55
Transferring what I say in my head "find the x values from the equation when t=0:5:55
to the code is what is irking me
  2 件のコメント
Stijn Haenen
Stijn Haenen 2020 年 4 月 18 日
I'm not sure what you want, the result of your script is an matrix 'x' with values corresponding to t=0:0.5:55.
with the function find you can find the position at which a certain relation holds, for example find(x==0) results in position 1 (the first element of x is equal to 0)
Michael Sabol
Michael Sabol 2020 年 4 月 18 日
Stijn,
thanks
it seems that my request wasn't as clear as it could be?
What I want is multiple x values that correspond to the t values in the matrix 0:5:55
so perhaps i cant use the find command for doing that?

サインインしてコメントする。

採用された回答

per isakson
per isakson 2020 年 4 月 18 日
Replace
find (x) = 0:5:55
by
x(1:round(5/dt):end,:)
This should work since 5/dt is a whole number. round takes care of a possible floating point error. When 5/dt isn't a whole number you can use the function interp1()

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by