I cant get this matlab function to work.
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
I have to use fsolve() to call this function.
I want to input a guess for fsolve() and I want two answers for each of the equations for Rblas4(1) and Rblas4(2).
my error reads:
error: 'T' undefined near line 19 column 18
error: called from
arco at line 19 column 14
My script it:
function Rblas4=arco(T)
p=51;
v=35;
n=50;
r=.08206;
spv=v/n;
Tca=150.87;
wa=1.002;
Tcc=304.2;
Pcc=72.9;
Pca=48.3;
wc=.225;
aa=.42747*((r*Tca)^2/Pca);
ac=.42747*((r*Tcc)^2/Pcc);
ba=.08664*((r*Tca)/Pca);
bc=.08664*((r*Tcc)/Pcc);
ma=.48508+1.55171*wa-.1561*(wa-1)^2;
mc=.48508+1.55171*wc-.1561*wc^2;
RBlas4(1)=(r*T(1))/(spv-ba)-aa*(1+ma*(1-sqrt(T(1)/Tca)))^2/(spv*(spv-ba))-p;
RBlas4(2)=(r*T(2))/(spv-bc)-ac*(1+mc*(1-sqrt(T(2)/Tcc)))^2/(spv*(spv-bc))-p;
end
THANK YOU
採用された回答
madhan ravi
2018 年 12 月 2 日
編集済み: madhan ravi
2018 年 12 月 2 日
EDITED
You should call the function properly with input T like shown below:
T=[3 8] %example
Rblas4=arco(T) %function call
function RBlas4=arco(T) %function definition
p=51;
v=35;
n=50;
r=.08206;
spv=v/n;
Tca=150.87;
wa=1.002;
Tcc=304.2;
Pcc=72.9;
Pca=48.3;
wc=.225;
aa=.42747*((r*Tca)^2/Pca);
ac=.42747*((r*Tcc)^2/Pcc);
ba=.08664*((r*Tca)/Pca);
bc=.08664*((r*Tcc)/Pcc);
ma=.48508+1.55171*wa-.1561*(wa-1)^2;
mc=.48508+1.55171*wc-.1561*wc^2;
RBlas4=[(r*T(1))/(spv-ba)-aa*(1+ma*(1-sqrt(T(1)/Tca)))^2/(spv*(spv-ba))-p; %change this line too
(r*T(2))/(spv-bc)-ac*(1+mc*(1-sqrt(T(2)/Tcc)))^2/(spv*(spv-bc))-p];
end
Note: matlab is case sensitive Rblas4 should be RBlas4
9 件のコメント
madhan ravi
2018 年 12 月 2 日
see edited answer it works
Rodrigo Blas
2018 年 12 月 2 日
Well, I got it to out put something. thank you
sorry but maybe i didnt ord my quesiton right.
but I'm trying to make it so that fsolve() solves for T(1) and T(2). They are both unknown variables. The two equations that are in the Rblas4 matrix are equal to zero
madhan ravi
2018 年 12 月 2 日
please upload the full code I'm having difficulty in understanding your question
Rodrigo Blas
2018 年 12 月 2 日
This is in the editor:
function Rblas4=arco(T)
p=51;
v=35;
n=50;
r=.08206;
spv=v/n;
Tca=150.87;
wa=1.002;
Tcc=304.2;
Pcc=72.9;
Pca=48.3;
wc=.225;
aa=.42747*((r*Tca)^2/Pca);
ac=.42747*((r*Tcc)^2/Pcc);
ba=.08664*((r*Tca)/Pca);
bc=.08664*((r*Tcc)/Pcc);
ma=.48508+1.55171*wa-.1561*(wa-1)^2;
mc=.48508+1.55171*wc-.1561*wc^2;
Rblas4=[(r*T(1))/(spv-ba)-aa*(1+ma*(1-sqrt(T(1)/Tca)))^2/(spv*(spv-ba))-p;
(r*T(2))/(spv-bc)-ac*(1+mc*(1-sqrt(T(2)/Tcc)))^2/(spv*(spv-bc))-p];
end
In the command window:
guess=[10 10]
guess =
10 10
>> fsolve('arco',guess)
error: invalid call to script C:\Users\rodri\arco.m
error: called from
fsolve at line 204 column 8
This is the full code with your adjustments. I want it to return the actual value of T for both equations in Rblas4 matrix. Both equations are equal to zero are both equal to zero and T(1) and T(2) are unknown
This is an example of what i want it to do:
This example shows how to solve two nonlinear equations in two variables. The equations are
Convert the equations to the form .
Write a function that computes the left-hand side of these two equations.
function F = root2d(x)
F(1) = exp(-exp(-(x(1)+x(2)))) - x(2)*(1+x(1)^2);
F(2) = x(1)*cos(x(2)) + x(2)*sin(x(1)) - 0.5;
Save this code as a file named root2d.m on your MATLAB® path.
Solve the system of equations starting at the point [0,0].
fun = @root2d;
x0 = [0,0];
x = fsolve(fun,x0)
Equation solved.
madhan ravi
2018 年 12 月 2 日
編集済み: madhan ravi
2018 年 12 月 2 日
change this
fsolve('arco',guess) % no strings to call the function ' ' should be @ -> function handle
to this
fsolve(@arco,guess)
Rodrigo Blas
2018 年 12 月 2 日
new error:
fsolve(@arco,guess)
error: 'k' undefined near line 5 column 21
error: called from
norm at line 5 column 6
fsolve at line 207 column 6
>>
madhan ravi
2018 年 12 月 2 日
wierd this is the answer I got
>> COMMUNITY
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
ans =
424.7032 458.5318
>>
Rodrigo Blas
2018 年 12 月 2 日
got it! THANK YOU SO MUCH!
What happened is I didnt click run.
You were very helpful :)
madhan ravi
2018 年 12 月 2 日
Anytime :)
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Genetic Algorithm についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
