ode45 say that return column vector using lsqcurvefit

I made 'lsqcurvefit optimization'. The file name is 'sample'. It works well.
And ' (a1 * 2 * f1 * pi * cos(2 * f1 * pi * t))' this formula is about velocity.
function FF = BF(t, a)
a1 = 5;
f1 = 0.5;
n = 1;
g = @(t, x)[(a1 * 2 * f1 * pi * cos(2 * f1 * pi * t));
-abs(a1 * 2 * f1 * pi * cos(2 * f1 * pi * t))*a(6)*x(2)*abs(x(2))^(n-1)-a(5)*a1 * 2 * f1 * pi *
cos(2 * f1 * pi * t)*abs(x(2))^n+a(4)*a1 * 2 * f1 * pi * cos(2 * f1 * pi * t)];
[t, xa] = ode45(@(t,x) g(t, x), t, [0 0]);
u = a1 * 2 * f1 * pi * cos(2 * f1 * pi * t);
FF = a(1)*u(:,1)+a(2)*xa(:,1)+a(3)*xa(:,2);
end
But I got velocity data by a experiment. So i substituted that formula to 'experiment data'.
The file name is sample_2.
I changed something.
First, i removed 'this (a1 * 2 * f1 * pi * cos(2 * f1 * pi * t))'. and i put 'velocity1 [9000x1 vector]'.
Second, i put 'velocity1_int' transposed for making [1x9000 vector].
But, it says '@(X,T)G(X,T) must return a column vector.'
Could you help me about this...
function FF = BF(velocity1, a, dk1)
n = 1;
t = (0:0.0006:5.3994)';
velocity1_int = velocity1';
g = @(x,t) [(-abs(velocity1_int)*a(4)*x(1)*abs(x(1))^(n-1)...
-a(5)*velocity1_int*abs(x(1))^n+a(6)*velocity1_int)];
[xa] = ode45(@(x,t) g(x,t), t, [0]);
FF = a(1)*velocity1+a(2)*dk1+a(3)*xa;
end

 采纳的回答

function FF = BF(velocity1, a, dk1)
n = 1;
t_int = (0:0.0006:5.3994)';
velocity1_int = velocity1';
[xa] = ode45(@(t_actual,x)g(t_actual,x,a,t_int,velocity1_int), t_int, [0]);
FF = a(1)*velocity1+a(2)*dk1+a(3)*xa;
end
function dx = g(t_actual,x,a,t_int,velocity1_int)
velocity1_actual = interp1(t_int,velocity1_int,t_actual);
dx = (-abs(velocity1_actual)*a(4)*x(1)*abs(x(1))^(n-1)...
-a(5)*velocity1_actual*abs(x(1))^n+a(6)*velocity1_actual);
end

更多回答(1 个)

g = @(x,t) [(-abs(velocity1_int)*a(4)*x(1)*abs(x(1))^(n-1);
-a(5)*velocity1_int*abs(x(1))^n+a(6)*velocity1_int)];

1 个评论

Thank you for respoding. But this is one formula not two formulas... So, I need other solution. Thank you so much...

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Nonlinear Least Squares (Curve Fitting) 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by