Filter löschen
Filter löschen

>> fun_f 입력 인수가 부족합니다. 오류 발생: fun_f (7번 라인) theta_d(1:​n)=theta(n​+1:2*n);

11 Ansichten (letzte 30 Tage)
세윤
세윤 am 15 Dez. 2022
Beantwortet: lazymatlab am 19 Apr. 2023
function theta_d=fun_f(t,theta)
global n m L cnt tmax g
theta_d=zeros(2*n,1);
theta_d(1:n)=theta(n+1:2*n);
for i=1:n
m_(i)=sum(m(i:n));
end
for i=1:n
for j=1:n
if i<j
a(i,j)= - m_(j)/m_(i)* L(j)/L(i)* cos(theta(i)-theta(j));
b_(i,j)= - m_(j)/m_(i)* L(j)/L(i)* theta_d(j)^2* sin(theta(i)-theta(j));
elseif i>j
a(i,j)= - L(j)/L(i)* cos(theta(j)-theta(i));
b_(i,j)= L(j)/L(i)* theta_d(j)^2* sin(theta(j)-theta(i));
else
a(i,j)= -1;
b_(i,j)= -g/L(i)* sin(theta(i));
end
end
end
b=zeros(n,1);
for i=1:n
b(i)=sum(b_(i,:));
end
theta_d(n+1:2*n)=-a\b;
if t>cnt*tmax/100
disp(cnt/1);
cnt=cnt+1;
end
clear
global n m L cnt tmax g
g=9.8;
cnt=0;
n=20;
m=[linspace(0.01, 0.01, n)];
L=[linspace(0.2, 0.2, n)];
theta0=[linspace(0.5, 1.0, n)];
theta_dot0=[linspace(0, 0, n)];
ini=[theta0 theta_dot0];
dt=0.01; tmax=10; tspan=[0:dt:tmax];
[t theta]=ode45(@fun_f, tspan, ini);
x=zeros(numel(tspan),n);y=zeros(numel(tspan),n);
for i=1:n
if i>=2
x(:,i)=x(:,i-1)+L(i)*sin(theta(:,i));
y(:,i)=y(:,i-1)-L(i)*cos(theta(:,i));
elseif i==1
x(:,i)=L(i)*sin(theta(:,i));
y(:,i)=-L(i)*cos(theta(:,i));
end
end
figure();
x2=2;
for k=1:x2:numel(tspan)
% plot([0 x(k,:)], [0 y(k,:)], '-o');
plot([0 x(k,:)], [0 y(k,:)]);
axis([-sum(L) sum(L) -sum(L) sum(L)]);
axis square;
pause(0.0005);
end
fun_f
입력 인수가 부족합니다.
오류 발생: fun_f (7번 라인)
theta_d(1:n)=theta(n+1:2*n);

Antworten (1)

lazymatlab
lazymatlab am 19 Apr. 2023
함수의 첫 줄은 함수의 입력과 출력을 선언하는 부분입니다.
function theta_d=fun_f(t,theta)
위와 같이 작성된 함수는, 입력인자 2개(t, theta)를 받아서 함수 내부에서 theta_d를 계산한 뒤 반환하는 함수입니다.
따라서 함수를 호출할 때에도 t와 theta가 전달되어야 합니다.

Kategorien

Mehr zu 그래픽스 객체 finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!