Nonlinear equation solver issue

조회 수: 1 (최근 30일)
Michael ODonnell
Michael ODonnell 2020년 4월 29일
댓글: Walter Roberson 2020년 8월 1일
I am trying to solve a system of nonlinear equations for two variables, in which some of the variables in the equations are vectors. When I run fsolve, I get the following error:
My function is defined as:
function F = root2d(x,m,g,L0,Kleg,u,T)
K_vert = x(1);
v = x(2);
F(:,1) = T - ((4.*sqrt(m./x(1))).*(pi-atan((x(2)./g).*sqrt(x(1)./m)))+(4.*x(2)./g));
F(:,2) = (x(1)./Kleg) - (1 + ((L0.*x(1)-sqrt(L0.^2.*x(1).^2-m.*x(1).*u.^2.*(pi-atan((x(2)./g).*sqrt(x(1)./m))).^2))./(m.*g+sqrt(m.^2.*g.^2+m.*x(1).*x(2).^2))));
end
Where the original equations are:
And, my code is:
g = 9.81;
m = 90.72;
uL = 0.364; % length of upper leg (m)
lL = 0.543; % length of lower leg (m)
L0 = uL+lL;
K_leg1 = 15;
K_leg2 = 0.715*m^0.67;
K_leg = (K_leg1+K_leg2)/2;
u = linspace(1.42,2.7,150);
f = 0.65 + 0.2.*u;
T = 1./f;
x0 = [18;3]';
for i = 1:150
x = fsolve(@(x)root2d(x,m,g,L0,K_leg,u(i),T(i)),x0);
K_vert(i) = x(1);
v(i) = x(2);
end
The value for K_vert has to be greater than 15, and the value for v should be in between 0 and 5, so I know that my starting values should not be the cause.
Any help would be appreciated! I've been trying to figure this out for hours.
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 4월 29일
Volunteers have an easier time answering when they are able to copy and paste code instead of having to type it in from a picture of the code.
Michael ODonnell
Michael ODonnell 2020년 4월 29일
Sorry, this is my first time posting. It is fixed now

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2020년 4월 29일
With those constants, solutions appear to be imaginary. The starting point becomes important.
g = 9.81;
m = 90.72;
uL = 0.364; % length of upper leg (m)
lL = 0.543; % length of lower leg (m)
L0 = uL+lL;
K_leg1 = 15;
K_leg2 = 0.715*m^0.67;
K_leg = (K_leg1+K_leg2)/2;
N = 150;
u = linspace(1.42,2.7,N);
f = 0.65 + 0.2.*u;
T = 1./f;
%x0 = [18;3]';
x0 = [10-1i, -1-1i];
K_vert = zeros(1,N);
v = zeros(1,N);
fval = zeros(N,2);
options = optimoptions('fsolve','Display','none');
for i = 1:N
[x, fval(i,:)] = fsolve(@(x)root2d(x,m,g,L0,K_leg,u(i),T(i)), x0, options);
K_vert(i) = x(1);
v(i) = x(2);
x0 = x;
end
Question: is your m^0.67 intended to represent m^(2/3) ?

Mohamed Amin Ibrahim
Mohamed Amin Ibrahim 2020년 8월 1일
편집: Walter Roberson 2020년 8월 1일
function ret=Code(lenchrom,bound)
%本函数将变量编码成染色体,用于随机初始化一个种群
% lenchrom input : 染色体长度
% bound input : 变量的取值范围
% ret output: 染色体的编码值
flag=0;
while flag==0
pick=rand(1,length(lenchrom));
ret=bound(:,1)'+(bound(:,2)-bound(:,1))'.*pick; %线性插值
flag=test(lenchrom,bound,ret); %检验染色体的可行性
end
  댓글 수: 2
Mohamed Amin Ibrahim
Mohamed Amin Ibrahim 2020년 8월 1일
hello am new to matlab but when i try to run this code i usually got error, please show me where there is error
Walter Roberson
Walter Roberson 2020년 8월 1일
What error message are you seeing?
MATLAB does not have a function named test so unless you have your own function test() then test(lenchrom,bound,ret) will fail.

댓글을 달려면 로그인하십시오.

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by