# Trying to assign a 3x1 matrix to the 1st iteration of a for loop.

6 ビュー (過去 30 日間)
Terry Poole 2020 年 9 月 17 日
コメント済み: Terry Poole 2020 年 9 月 17 日
clear all; close all; clc;
airspeed = 200;
windspeed = 15;
angleofattack = 15*(pi/180);
sideslip = 10*(pi/180);
roll = 12*(pi/180);
pitch = 6*(pi/180);
yaw = 0*(pi/180);
airspeed_vector= [200;0;0];
windspeed_vector = [0;15;0];
[bankangle,flightpathangle]=...
angleofattack, sideslip, roll, pitch, yaw)
%
%Stuck here, trying to use Euler method to integrate
%navigation_airspeed_vector over a time of 60 seconds with a .01 step
x0=0;%initial value for x
y0=navigation_airspeed_vector;%initial value for y (3x1 double)
xn=60;%final vaule for x(where we want to end up)
h=0.01;%This is the choice of h that changes for different parts
n=(xn-x0)/h;
x=zeros(n+1,1);
y=zeros(n+1,1);
x(1)=x0;
y(1)=y0;%%Can't figure out how to assign the 3x1 matrix to this variable,
%I'm sure it has something to do with y being a 6000x1 matrix but I can't
%figure out what to do to fix it.
for k=1:n
x(k+1)=x(k)+h;
y(k+1)=y(k)+h*(x(k)*y(k));
disp(y);
end
function [bankangle,flightpathangle]=...
Cwindtobody = [cos(angleofattack)*cos(sideslip), -cos(angleofattack)...
*sin(sideslip), -sin(angleofattack); sin(sideslip), cos(sideslip),...
0; sin(angleofattack)*cos(sideslip), -sin(angleofattack)...
*sin(sideslip), cos(angleofattack)]^(-1);
-sin(pitch); sin(roll)*sin(pitch)*cos(yaw)-cos(roll)*sin(yaw),...
sin(roll)*sin(pitch)*sin(yaw)+cos(roll)*cos(yaw), sin(roll)...
*cos(pitch); cos(roll)*sin(pitch)*cos(yaw)+sin(roll)...
*sin(yaw), cos(roll)*sin(pitch)*sin(yaw)-sin(roll)...
*cos(yaw), cos(roll)*cos(pitch)];
end
angleofattack, sideslip, roll, pitch, yaw)
Cwindtobody = [cos(angleofattack)*cos(sideslip), -cos(angleofattack)...
*sin(sideslip), -sin(angleofattack); sin(sideslip), cos(sideslip),...
0; sin(angleofattack)*cos(sideslip), -sin(angleofattack)...
*sin(sideslip), cos(angleofattack)]^(-1);
-sin(pitch); sin(roll)*sin(pitch)*cos(yaw)-cos(roll)*sin(yaw),...
sin(roll)*sin(pitch)*sin(yaw)+cos(roll)*cos(yaw), sin(roll)...
*cos(pitch); cos(roll)*sin(pitch)*cos(yaw)+sin(roll)...
*sin(yaw), cos(roll)*sin(pitch)*sin(yaw)-sin(roll)...
*cos(yaw), cos(roll)*cos(pitch)];
end

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

### 採用された回答

Dana 2020 年 9 月 17 日
If y is an array that's tracking values of a 3-element vector as you iterate on k, then you need to make y a matrix. If I've understood this right, you want to do something like:
x=zeros(n+1,1);
%y=zeros(n+1,1); % the way you did it
y=zeros(3,n+1); % the correct way: now y(:,k) corresponds to the k-th 3-element vector
x(1)=x0;
%y(1)=y0; % the way you did it
y(:,1)=y0; % the correct way
for k=1:n
x(k+1)=x(k)+h;
%y(k+1)=y(k)+h*(x(k)*y(k)); % the way you did it
y(:,k+1)=y(:,k)+h*(x(k)*y(:,k)); % the correct way
disp(y);
end
##### 1 件のコメント表示 なし非表示 なし
Terry Poole 2020 年 9 月 17 日
That worked! Thanks, a bunch!

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

### カテゴリ

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

### Community Treasure Hunt

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

Start Hunting!