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); ''
2 ビュー (過去 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!