How to solve a function with different ranges
古いコメントを表示
I have a variable that is composed of two functions for different ranges:
alfa_ox = 1/15*C_ox for 0 <= C_ox <= 15
alfa_ox = 1 for C_ox > 15
When I imply this in Matlab, it doesnt consider the second condition (that alfa can't be bigger than 1). How can I solve that?
C_ox = [16;15;7.5;2;7.5;15;15];
if C_ox > 15
alfa = 1
else alfa = 1/15.*C_02
end
Output:
alfa =
1.0667
1.0000
0.5000
0.1333
0.5000
1.0000
1.0000
6 件のコメント
Scott MacKenzie
2021 年 6 月 15 日
What is C_02?
Delia Bosshart
2021 年 6 月 15 日
Scott MacKenzie
2021 年 6 月 15 日
Is it a vector? It might help if you provide the data.
Scott MacKenzie
2021 年 6 月 15 日
編集済み: Scott MacKenzie
2021 年 6 月 15 日
And BTW, your if-expression is an array. That's probably not what is itended.
Delia Bosshart
2021 年 6 月 15 日
Scott MacKenzie
2021 年 6 月 15 日
編集済み: Scott MacKenzie
2021 年 6 月 15 日
Sorry for the string of comments here, but your question uses the expression
1/15*C_ox
In your code we see
1/15.*C_02
Please clarify.
採用された回答
その他の回答 (1 件)
Try
C_ox = [16;15;7.5;2;7.5;15;15];
C_ox(C_ox<=15)=C_ox(C_ox<=15)/15;
C_ox(C_ox>15)=1
カテゴリ
ヘルプ センター および File Exchange で Guidance, Navigation, and Control (GNC) についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!