Function doesn't work in another file

6 ビュー (過去 30 日間)
Joanna Zajac
Joanna Zajac 2021 年 11 月 13 日
コメント済み: Joanna Zajac 2021 年 11 月 13 日
Hello!
I have problem, i'm trying to to make function working in another file, but i always have this error:
Error in wysokosc (line 6)
[Th(i), Ph(i), Roh(i)]= atmosfera_wzorcowa(H(i));
I don't know how to fix it. Somebody can tell me where i make mistake?
Here i put my function:
function [Th, Ph, Roh] = atmosfera_wzorcowa(H)
g = 9.80665;
R = 287.05287;
if H>=0 & H<=11000
beta = -0.0065;
Tb = 288.15;
Pb = 101325;
Hb = 0;
Th=Tb+beta*(H-Hb);
Ph=Pb*((1+((beta/Tb)*(H-Hb)))^(-g/(beta*R)))
Roh = Ph1/(R*Th);
elseif H>11000 & H<=20000
beta = 0;
Tb = 216.65;
Pb = 22632;
Hb = 11000;
Th=Tb+beta*(H-Hb);
Ph=Pb*exp(-g/(R*Th)*(H-Hb))
else
disp('Wprowadzono zle dane')
end
Roh = Ph/(R*Th);
end
and my file
clear
clc
H = 0:1000:20000;
n = length(H);
for i = 1:n
[Th(i), Ph(i), Roh(i)]= atmosfera_wzorcowa(H(i));
end

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 11 月 13 日
When I run your code, I get the following error:
Unrecognized function or variable 'Ph1'.
Roh = Ph1/(R*Th);
Is that just a typo? Should your equation be using Ph instead of Ph1? When I change it to be Ph, your code runs for me.
  1 件のコメント
Joanna Zajac
Joanna Zajac 2021 年 11 月 13 日
You are right, i missed it. Thank you!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by