How would I integrate different values into 4 tables?
이전 댓글 표시
I have this code
clc
clear
close
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;
v = zeros(length(t),4);
vx = zeros(length(t),4);
vy= zeros(length(t),4);
x = zeros(length(t),4);
y = zeros(length(t),4);
v(1,1) = 1200;
vx(1,1) = v(1,1)*cos(a);
vy(1,1) = v(1,1)*sin(a);
x(1,1)=0;
y(1,1)=0;
for i=2:length (t)
x(i,1) = x(i-1,1)+vx(i-1,1)*dt-.5*k*v(i-1,1).^2*cos(a)*dt.^2;
y(i,1) = y(i-1,1)+vy(i-1,1)*dt-.5*k*v(i-1,1).^2*sin(a)*dt^2-0.5*g*dt.^2;
vx(i,1) = vx(i-1,1)-k*v(i-1,1).^2*cos(a)*dt;
vy(i,1) = vy(i-1,1)-k*v(i-1,1).^2*sin(a)*dt-g*dt;
a=atan(vy(i,1)./vx(i,1));
v(i,1)=sqrt(vx(i,1).^2+vy(i,1).^2);
end
vx(1:round(5/dt):end,:)
vy(1:round(5/dt):end,:)
x(1:round(5/dt):end,:)
y(1:round(5/dt):end,:)
That results in
ans =
919.25 0 0 0
919.25 0 0 0
919.25 0 0 0
919.25 0 0 0
919.25 0 0 0
919.25 0 0 0
919.25 0 0 0
919.25 0 0 0
919.25 0 0 0
919.25 0 0 0
919.25 0 0 0
919.25 0 0 0
ans =
771.35 0 0 0
610.35 0 0 0
449.35 0 0 0
288.35 0 0 0
127.35 0 0 0
-33.65 0 0 0
-194.65 0 0 0
-355.65 0 0 0
-516.65 0 0 0
-677.65 0 0 0
-838.65 0 0 0
-999.65 0 0 0
ans =
0 0 0 0
4596.27 0 0 0
9192.53 0 0 0
13788.80 0 0 0
18385.07 0 0 0
22981.33 0 0 0
27577.60 0 0 0
32173.87 0 0 0
36770.13 0 0 0
41366.40 0 0 0
45962.67 0 0 0
50558.93 0 0 0
ans =
0 0 0 0
3454.23 0 0 0
6103.45 0 0 0
7947.68 0 0 0
8986.90 0 0 0
9221.13 0 0 0
8650.35 0 0 0
7274.58 0 0 0
5093.81 0 0 0
2108.03 0 0 0
-1682.74 0 0 0
-6278.52 0 0 0
My issues is whenever I change the K value to [2e-6,10e-6, or 20e-6] it results in the first column changing to the respective k values. However, if I change the x(i,1) positions to say x(i,2) for [2e-6] (and all subsequent notations) then I get every k = 2e-6 value in the 2nd column and the first column becomes zero. Question is how do I get the answers to add on to the table made from previous calculations?
댓글 수: 2
BALAJI KARTHEEK
2020년 4월 20일
Just give sample image of the table (what ur expecting in the result), so it will easy to understand and modify the code written by u..
Michael Sabol
2020년 4월 20일
채택된 답변
추가 답변 (1개)
darova
2020년 4월 20일
0 개 추천
Try this solution

댓글 수: 2
Michael Sabol
2020년 4월 20일
darova
2020년 4월 20일
It doesn't matter. More reasonable be inside first
for j=1:length (k)
k=K1(j);
for i=2:length (t)
% code
카테고리
도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!