フィルターのクリア

Function file not behaving

2 ビュー (過去 30 日間)
Thomas Humphrey
Thomas Humphrey 2012 年 1 月 13 日
コメント済み: Michael 2024 年 2 月 7 日
When trying to run this function, every time it comes up with an error which I'm not sure where it is.
I'm calling it using the code, and getting the error:
[BPE] = BPE(T_f, X_f)
And I'm getting these errors:
??? Attempted to access BPE(69.81,42); index must be a positive integer or logical.
?? Index exceeds matrix dimensions
??? Attempted to access BPE(69,42); index out of bounds because numel(BPE)=1.
T_f = 69.81 and X_f = 42
This is my function file:
function [BPE] = BPE(T, X)
% A function to calculate The Boiling point elevation in degrees Celcius
A = (8.325e-2 + 1.883e-4 * T + 4.02e-6 * T^2);
B = (-7.625e-4 + 9.02e-5 * T - 5.2e-7 * T^2);
C = (1.522e-4 - 3e-6 * T - 3e-8 * T^2);
BPE = 100 * A*X + B*X^2 + C*X^3;
end
Any thoughts as to why this is failing?
Thanks in advance.
  1 件のコメント
Michael
Michael 2024 年 2 月 7 日
Anyone please clarify to me what T are we using in the below function?
function [rise] = BPRfunc(T,x)
A = (8.325e-2 + 1.883e-4*T + 4.02e-6*T.^2);
B = (-7.625e-4 + 9.02e-5 * T - 5.2e-7 * T.^2);
C = (1.522e-4 - 3e-6 * T - 3e-8 * T.^2);
rise = A*x + B*x^2 + C*x^3;
end
If it is the boiling point temperature of the feed water (seawater), isn't it dependent on BPE? Is it a scalar value?
Also, I think T changes with effect number?

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

採用された回答

Wayne King
Wayne King 2012 年 1 月 13 日
Don't name your output variable the same as the function. Because after you output BPE once, then it's a variable in the workspace and you subsequently try to access a non-integer element of a variable (a scalar in this case).
Change the name of the output argument in your function.
function [BP] = BPE(T, X)
% A function to calculate The Boiling point elevation in degrees Celcius
A = (8.325e-2 + 1.883e-4 * T + 4.02e-6 * T^2);
B = (-7.625e-4 + 9.02e-5 * T - 5.2e-7 * T^2);
C = (1.522e-4 - 3e-6 * T - 3e-8 * T^2);
BP = 100 * A*X + B*X^2 + C*X^3;
end
  1 件のコメント
Thomas Humphrey
Thomas Humphrey 2012 年 1 月 13 日
Great, It's working now
Stupid me
Thanks a lot
Tom

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

その他の回答 (1 件)

Jaap
Jaap 2012 年 1 月 13 日
BPE is both a function and an variable. Matlab can't make out which one you're referring to. try BPE_v = BPE(....)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by