フィルターのクリア

I dont know why it is saying there are not enough input arguments and then there are two errors that have no description as to what's wrong please help

3 ビュー (過去 30 日間)
CONNOR
CONNOR 2023 年 11 月 27 日
編集済み: Torsten 2023 年 11 月 27 日
close all, clear, clc
load("EnvironmentalForcing.mat")
t = linspace(0,60,1465);
Bmax = 1;
uL = 6;
uI = 10;
e = 0.001;
Ap = 5000;
Pi = 1.33*30*(-0.35968 + 0.10789*15-0.00214*15*15)*30;
Si = Pi/Ap;
Li = 0.01;
Ii = 0;
Ri = uI*Ii;
Bi = 1;
Te = -0.35968 + 0.10789.*T - 0.00214.*T.^2;
for i = 1:length(T)
if T(i)>0 && T(i)<35
Tb(i) = (0.000241*(T(i)^2.06737))*((35-T(i))^0.72859);
end
end
B = Bmax*Tb;
y0 = [Si; Li; Ii; Ri; Pi];
[t, y] = rungeKuttaSystem(@mySystemODEs, tspan, y0);
Not enough input arguments.

Error in solution>mySystemODEs (line 26)
dPldt = (1.33*t)*Te;

Error in solution>rungeKuttaSystem (line 45)
k1 = odeFunc(t(n), y(:, n));
function dydt = mySystemODEs(t, B, uL, uI, e, Ap, Te)
% Define your system of ODEs
dPldt = (1.33*t)*Te;
dPbdt = (0.1724*Pb - 0.0000212*Pb^2)*Te;
dPdt = dPbdt +dPldt;
dSdt = (-B*S*I)+(dPdt*(1/Ap));
dLdt = (B*S*I)-(uL^-1*L)+e;
dIdt = (uL^-1*L)-(uI^-1*I);
dRdt = uI^-1*I;
dydt = [dSdt; dLdt; dIdt; dRdt; dPdt];
end
function [t, y] = rungeKuttaSystem(odeFunc, tspan, y0)
q = length(y0);
N = length(tspan);
t0 = tspan(1);
h = tspan(2) - tspan(1);
t = zeros(N, 1);
y = zeros(q, N);
t(1) = t0;
y(:, 1) = y0;
for n = 1:N-1
k1 = odeFunc(t(n), y(:, n));
k2 = odeFunc(t(n) + 0.5*h, y(:, n) + 0.5*h*k1);
k3 = odeFunc(t(n) + 0.5*h, y(:, n) + 0.5*h*k2);
k4 = odeFunc(t(n) + h, y(:, n) + h*k3);
for j = 1:q
y(j, n+1) = y(j, n) + h*(k1(j) + 2*k2(j) + 2*k3(j) + k4(j))/6;
end
t(n+1) = t(n) + h;
end
end
% I think I linked the file for the Enviromental file at the top so now
% you should be able to execute the code
  3 件のコメント
CONNOR
CONNOR 2023 年 11 月 27 日
I forgot to link the external file it should be linked now
Torsten
Torsten 2023 年 11 月 27 日
編集済み: Torsten 2023 年 11 月 27 日
function dydt = mySystemODEs(t, B, uL, uI, e, Ap, Te)
Your function where you supply the derivatives expects 7 input arguments, but you call it with only 2:
k1 = odeFunc(t(n), y(:, n));
If you supply uL,uI,e,Ap and Te in the script part of your code, you can pass the missing 5 parameters as
[t, y] = rungeKuttaSystem(@(t,y)mySystemODEs(t,y,uL, uI, e, Ap, Te), tspan, y0);
Further Pb is undefined in the setting
dPbdt = (0.1724*Pb - 0.0000212*Pb^2)*Te;
And B is a vector of size (5x1) in
dSdt = (-B*S*I)+(dPdt*(1/Ap));
Thus a lot of confusion in your coding.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 11 月 27 日
function dydt = mySystemODEs(t, B, uL, uI, e, Ap, Te)
Naming a variable in the function header does not cause the variable of the same name in the caller to be automatically imported.
In fact it is quite the opposite in MATLAB: when a variable is named in a function header, then MATLAB will never search elsewhere for the variable inside the body of the function. This includes the case of nested functions and shared variables: if you declare a variable in the function header of a nested function, then MATLAB will not look for that variable in the nesting function.
Any variable that is named in a function header has three possibilities:
  • if the variable has been assigned to inside the function, then the variable is associated with what was assigned, not matter what was or was not passed in at the corresponding position
  • otherwise, if the caller provided at least as many parameters as the relative offset of the variable, then the variable will be assigned the corresponding input completely positionally
  • otherwise, if the caller did not provide as many parameters as the relative offset of the variable, then when the value of the variable is needed, an error message will be given (and no searching for a variable with the same name will be done)
Variables that are not named in a function header sometimes might be searched for in an outside context:
  • inside nested functions, then variables in nesting functions might be searched
  • functions with the required name would be searched for (since it is often not immediately obvious that the name is a variable insted of a function)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by