Having different value for the same function

I have a simple function
P_MCH = [0.20598017,0.270460009,0.313455273];
P_TOL = [0.20598017,0.270460009,0.313455273];
P_H2 = [4.58803966,4.459079983,4.373089453];
Rp = @(p) p(1)* p(2)*P_MCH.*(1-P_TOL.*P_H2.^3/(P_MCH*316.8159);
While running the Rp is calculated as 0.74409.
In excel it is 0.715944
Can you help?

3 件のコメント

Davide Masiello
Davide Masiello 2023 年 8 月 7 日
編集済み: Davide Masiello 2023 年 8 月 7 日
What are the values of p(1) and p(2)?
Also, what do you want do do with the arrays?
It seems you'd want to do operations element by element and then sum?
Walter Roberson
Walter Roberson 2023 年 8 月 7 日
Are you sure you want to use the / operator and not the ./ operator ?
Aditya
Aditya 2023 年 8 月 22 日
Can you provide the values of p(1) and p(2)?

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

回答 (1 件)

Karan Singh
Karan Singh 2025 年 2 月 1 日

0 投票

Looks like your equation is missing parentheses, and now that I think about it, Excel might handle calculations differently—like summing the numerator and denominator before dividing. MATLAB gives 0.74409, probably because it's using matrix division (/) instead of element-wise division (./), which changes how the calculation works and introduces a scalar value. Meanwhile, Excel gives 0.715944, which makes sense if it's actually doing element-wise division and summing things correctly. So yeah, maybe the equation formatting is the issue?

カテゴリ

製品

リリース

R2023a

タグ

質問済み:

2023 年 8 月 7 日

回答済み:

2025 年 2 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by