我想要知道我的这份代​码(两个脚本)哪里需​要修改,为什么会出现​提示的错误,谢谢!

4 ビュー (過去 30 日間)
南羽
南羽 2024 年 4 月 11 日
回答済み: cdarling 2024 年 7 月 17 日
脚本1
function dydt = jiaoyijizhi(t, y, Rg, E, T, Cg, A, Alpha, K, Cr, Ir, Rq, Cq, U, P, Fc, L, beta)
dydt = zeros(3, 1);
dydt(1) = y(1)*(y(1) - 1)*(E*y(2) - K + K*y(2) + Rg*y(2) + Alpha*Cg + Alpha*K - Alpha*P - Alpha*T + A*Alpha*y(2) - Alpha*E*y(2) - Alpha*K*y(2) + Alpha*P*y(2) - Alpha*Rg*y(2));
dydt(2) = y(2)*(1 - y(2))*(Cr - Cq - Ir + Rq + A*y(1) + Fc*y(1) + U*y(3) + Alpha*P*y(1));
dydt(3) = y(3)*(1 - y(3))*(L*beta - E*y(2) + E*beta*y(2));
end
脚本2
figure(1);
Rg = 70; E = 100; T = 5; Cg = 20; A = 20; Alpha = 0.3; Cr = 80; Ir = 30; Rq = 50; Cq = 0; L = 100;
[t, y] = ode45(@(t, y) jiaoyijizhi(t, y, Rg, E, T, Cg, A, Alpha, K, Cr, Ir, Rq, Cq, U, P, Fc, L, beta), [0 50], [0.1 0.1 0.1]);
plot3(y(:,1), y(:,2), y(:,3), 'rh-', 'linewidth', 1);
hold on;
Rg = 70; E = 100; T = 5; Cg = 20; A = 20; Alpha = 0.6; Cr = 80; Ir = 30; Rq = 50; Cq = 0; L = 100;
[t, y] = ode45(@(t, y) jiaoyijizhi(t, y, Rg, E, T, Cg, A, Alpha, K, Cr, Ir, Rq, Cq, U, P, Fc, L, beta), [0 50], [0.1 0.1 0.1]);
plot3(y(:,1), y(:,2), y(:,3), 'g--', 'linewidth', 1);
hold on;
Rg = 70; E = 100; T = 5; Cg = 20; A = 20; Alpha = 0.9; Cr = 80; Ir = 30; Rq = 50; Cq = 0; L = 100;
[t, y] = ode45(@(t, y) jiaoyijizhi(t, y, Rg, E, T, Cg, A, Alpha, K, Cr, Ir, Rq, Cq, U, P, Fc, L, beta), [0 50], [0.1 0.1 0.1]);
plot3(t,y(:,1), y(:,2), y(:,3), 'b:', 'linewidth', 1);
hold on;
提示错误:
出错 jiaoyijizhi1>@(t,y)jiaoyijizhi(t,y,Rg,E,T,Cg,A,Alpha,K,Cr,Ir,Rq,Cq,U,P,Fc,L,beta) (第 4 行)
[t, y] = ode45(@(t, y) jiaoyijizhi(t, y, Rg, E, T, Cg, A, Alpha, K, Cr, Ir, Rq, Cq, U, P, Fc, L, beta), [0 50], [0.1 0.1 0.1]);
出错 odearguments (第 92 行)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.
出错 ode45 (第 104 行)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
出错 jiaoyijizhi1 (第 4 行)
[t, y] = ode45(@(t, y) jiaoyijizhi(t, y, Rg, E, T, Cg, A, Alpha, K, Cr, Ir, Rq, Cq, U, P, Fc, L, beta), [0 50], [0.1 0.1 0.1]);
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2024 年 4 月 11 日
Variables K, U, P, Fc, and beta are not defined in your code.

サインインしてコメントする。

回答 (1 件)

cdarling
cdarling 2024 年 7 月 17 日
报错信息如下,第一行即说明了问题,在你的程序中,没有定义K是什么
因此在脚本2中第三行,程序不知道要给jiaoyijizhi传入什么K值
应该像第二行中定义其他值一样,定义K的值
函数或变量 'K' 无法识别。
出错
jiaoyijizhi>@(t,y)jiaoyijizhi(t,y,Rg,E,T,Cg,A,Alpha,K,Cr,Ir,Rq,Cq,U,P,Fc,L,beta)
(4 )
[t, y] = ode45(@(t, y) jiaoyijizhi(t, y, Rg, E, T, Cg, A, Alpha, K, Cr,
Ir, Rq, Cq, U, P, Fc, L, beta), [0 50], [0.1 0.1 0.1]);
出错 odearguments (92 )
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.
出错 ode45 (104 )
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode,
tspan, y0, options, varargin);
出错 jiaoyijizhi (4 )
[t, y] = ode45(@(t, y) jiaoyijizhi(t, y, Rg, E, T, Cg, A, Alpha, K, Cr,
Ir, Rq, Cq, U, P, Fc, L, beta), [0 50], [0.1 0.1 0.1]);
另外,看你的报错信息,你可能把“脚本1”的文件名写成“jiaoyijizhi1”了,但它的函数名是“jiaoyijizhi”,差一个1,这里可能也有点小问题

カテゴリ

Help Center および File ExchangeBig Data Processing についてさらに検索

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!