1

我正在尝试解决一个非常大的耦合非线性方程组。在此线程和 Matalb 的相关帮助(第一个示例)之后,我尝试编写以下代码:

%% FSOLVE TEST #2
clc; clear; close all
%%
global a0 a1 a2 a3 a4 h0 TM JA JB
a0 = 2.0377638272727268;
a1 = -7.105521894545453;
a2 = 9.234000147272726;
a3 = -5.302489919999999;
a4 = 1.1362478399999998;
h0 = 45.5;
TM = 0.00592256;
JA = 1.0253896074561006;
JB = 1.3079437258774012;

%% 
global N
N = 5;

XA = 0;
XB = 15;

dX = (XB-XA)/(N-1);
XX = XA:dX:XB;

y0 = JA:(JB-JA)/(N-1):JB;

plot(XX,y0,'o')
[x,fval] = fsolve(@nlsys,y0);

其中函数nlsys如下:

function S = nlsys(x)
global a1 a2 a3 a4 N TM h0 dX JA JB

H = h0^2/12;
e = cell(N,1);

for i = 2:N-1    
    D1 = (x(i+1) - x(i-1))./2./dX;
    D2 = (x(i+1) + x(i-1) - 2.*x(i))./(dX^2);
     f = a1 + 2*a2.*x(i) + 3*a3.*x(i).^2 + 4*a4.*x(i).^3;
     g = - H.* (a1 + 2*a2.*x(i) + 3*a3.*x(i).^2 + 4*a4.*x(i).^3)./(x(i).^5);
     b = (H/2) .* (5*a1 + 8*a2.*x(i) + 9*a3.*x(i).^2 + 8*a4.*x(i).^3)./(x(i).^6);

     e{i} = @(x) f + b.*(D1.^2) + g.*D2 - TM;               
end

e{1} = @(x) x(1) - JA;
e{N} = @(x) x(N) - JB;
S = @(x) cellfun(@(E) E(x), e);

当我运行程序时,Matlab 给出以下错误:

使用 fsolve 时出错(第 280 行) FSOLVE 要求用户函数返回的所有值都是双精度数据类型。

fsolve_test2 中的错误(第 32 行)[x,fval] = fsolve(@nlsys,y0);

我的错误在哪里?提前致谢。

柏图斯

4

0 回答 0