solve a function on intervalls
13 ビュー (過去 30 日間)
古いコメントを表示
Hello everyone,
today I have I problem which I could not solve because of the limitation of my matlab skills. I am sure Matlab can do this . So time to learn something new - I hope you can teach me how to :D
I will try to explain what I want to do first :)
My function is F(s,x_i). The function is defined on three intervals for s which are known (s<s_a, s_a<=s<=s_b, s_b<s). X is a set of known parameters. We have two known x called x_1 and x_2 which are different. The values of the intervals s_a and s_b are known but different for both x parameter sets. S is what we are looking for. To solve this I have the condition of the sum of F(s,x_1) and F(s,x_2) to match a known value F_total.
So F_total = F(s,x_1) + F(s,x_2) is what we want so solve to get our s.
The simple and stupid idea was to increase s from minimum value till we reach F_total. But this was much too slow, so I need a more efficient way to get the solution :(
I hope you can help me, thank you very much in advance!
Marius
7 件のコメント
Walter Roberson
2020 年 6 月 26 日
F = @(s) (s<s_a) .* F1(s) + (s_a <= s & s < s_b) .* F2(s) + (s_b < s) .* F3(s);
However, this will fail if any of the functions could return infinity or nan when invoked "when they shouldn't be". For example if F2 included 1/s and that wasn't supposed to be a problem because s_a and s_b where chosen such that the range for F2 excluded s = 0, then there would be a problem.
For cases that can include infinity or nan, you need more complicated phrasings such as
H = {@F1, @F2, @F3};
F = @(s) H{cumsum([1, s_a <=s, s_b <s])}(s)
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!