Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Can anyone help me with this error please? '' In an assignment A(I) = B, the number of elements in B and I must be the same. Error in RunFib (line 21) JTime(j) = integral(f,0,t(1,j),'Waypoints',t)./ t(1,j); ''
조회 수: 3 (최근 30일)
이전 댓글 표시
My code is :
function RunFib
x0=[12 5];
b = 3 ;
tspan = 0 : 0.001 : 10 ;
t0 =tspan(1);
tf=tspan(length(tspan));
A=1/(tf-t0);
[t,x]=ode45(@Fib, tspan , x0 , [] , 3);
a1 = ( 15*x(:,1) - 3.*x(:,1).*x(:,2) );
b1 = ( -5*x(:,2) + 0.5*x(:,1).*x(:,2) );
f = @(tspan) ( A.* (a1.* (a1 .* (15 - 3.*x(:,2)) + b1 .* (0.5 .* x(:,2)) ) + b1 .*
( a1 .* (-3 .* x(:,1)) + b1 .* (-5 + 0.5.* x(:,1)) ) ).^2 ./ (a1.^2 + b1.^2).^3 );
t= (0:0.5:10);
N = length(t);
JTime = zeros(1,N);
for j = 1:N
JTime(j) = integral(f,0,t(1,j),'Waypoints',t)./ t(1,j);
end
figure(2)
semilogy(t,JTime,'r+-')
1;
function dx = Fib(t,x,b)
dx=zeros(2,1);
dx0 = 15 * x(1) - b * x(1).* x(2);
dx1 = -5 * x(2) + 0.5 * x(1).* x(2);
end
댓글 수: 0
답변 (1개)
Walter Roberson
2015년 8월 31일
편집: Walter Roberson
2015년 8월 31일
Your f takes an input and ignores it and returns something that is size(x,1) elements. The integral of this is probably not going to be a single value.
댓글 수: 4
Walter Roberson
2015년 8월 31일
You are currently doing the equivalent of
f = @(x) [17 9]
which is to say your function f ignores its input and always returns the same thing, a list of values. What are you expecting that the result would be?
Also, you currently have
function dx = Fib(t,x,b)
dx=zeros(2,1);
dx0 = 15 * x(1) - b * x(1).* x(2);
dx1 = -5 * x(2) + 0.5 * x(1).* x(2);
end
That routine computes dx0 and dx1 but then it throws them away and returns the zeros(2,1) from the
dx=zeros(2,1);
You need
function dx = Fib(t,x,b)
dx0 = 15 * x(1) - b * x(1).* x(2);
dx1 = -5 * x(2) + 0.5 * x(1).* x(2);
dx = [dx0; dx1];
end
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!