这应该是一个倒退的欧拉绘图仪,但它不起作用:
Warning: Explicit solution could not be found.
> In solve at 83
In u1cBAEUL at 29
??? In an assignment A(I) = B, the number of elements
in B and
I must be the same.
Error in ==> u1cBAEUL at 45
q1(i+1) = a;
我使用solve
:
clear all, close all, clc
stl= 0.05; % steplength
nos = 5000; % number of steps
q1 = zeros(1,nos);
q2 = zeros(1,nos);
q1v = zeros(1,nos);
q2v = zeros(1,nos);
q1a = zeros(1,nos);
q2a = zeros(1,nos);
% Starting positions
a=0.5;
q1(1) = 1-a;
q2(1) = 0;
q1v(1) = 0;
q2v(1) = sqrt((1+a)/(1-a));
% P is inertia, and has the same vector components as the body velocity
for i=1:nos-1
[q1a(i),q2a(i)] = u1FUNC(q1(i),q2(i));
q1v(i+1) = q1v(i) + q1a(i).*stl;
q2v(i+1) = q2v(i) + q2a(i).*stl;
[a,b] = solve ('a = q1(i) + stl*((q1v(i+1) + stl*(u1FUNC(a,b))))','b = q2(i) + stl*((q2v(i+1) + stl*(u1FUNC(a,b))))');
% q1'' = v1'
% v1 = f(q1,q2)
%
% q1n+1 = q1n + stl*v1n+1
% v1n+1 = v1n + stl*f(q1n+1,q2n+1)
%
% q2'' = v2'
% v2 = g(q1,q2)
%
% q2n+1 = q2n + stl*v2n+1
% v2n+1 = v2n + stl*g(q1n+1,q2n+1)
%
% q1n+1 = q1n + stl(v1n + stl*f(q1n+1,q2n+1)
% q2n+1 = q2n + stl(v2n + stl*g(q1n+1,q2n+1)
q1(i+1) = a;
q2(i+1) = b;
end
我应该使用fsolve
代替solve
吗?