solving trascendental equations, proper setting
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hello everybody,
I'd like to solve for y = y(x) the following equation
d log( y ) / d x + y = 1 + f
with f = f(x).
f is a 1D numerically known array, I don't know its nalytical form.
I cannot set properly solve or fzero.
Can you help me, please?
Patrizio
採用された回答
Ameer Hamza
2020 年 6 月 14 日
編集済み: Ameer Hamza
2020 年 6 月 14 日
This is a differential equation and you can use symbolic toolbox to find an anayltical solution
syms y(x) f
eq = diff(log(y), x) + y == 1 + f;
sol = dsolve(eq);
Result
>> sol
sol =
(exp((C1 + x)*(f + 1))*(f + 1))/(exp((C1 + x)*(f + 1)) + 1)
f + 1
Following shows how to get a numerical solution using ode45
syms y(x) f
eq = diff(log(y), x) + y == 1 + f;
sol = dsolve(eq);
odeFun = matlabFunction(odeToVectorField(eq), 'Vars', {'t', 'Y', 'f'});
tspan = [0 10]; % time span for numerical solution
ic = 1; % initial condition: y(0)==1
fv = 1; % numerical solution for f=1
[t, y] = ode45(@(t, y) odeFun(t, y, fv), tspan, ic);
plot(t, y);
7 件のコメント
PatrizioGraziosi
2020 年 6 月 14 日
編集済み: PatrizioGraziosi
2020 年 6 月 14 日
Thank you Ameer!
In the system I'm stuying, for each 'x' value there is one value for 'f' and one value for 'y'.
I mean, there is a f(x) that I know and a y(x) I don't know but for each 'x' value there are only one 'f' and one 'y' . I know f(x) and the relation between f(x) and y(x), and should find y(x).
As far as I understand, the tspan plays the role of the 'x' variable and I get a y(x) for each 'fv' but this not actually the case: for each 'x' value I have also a different 'fv' value.
Hope this makes my problem clearer. If I have misunderstood your answer, sorry.
About the symbolic toolbok lines you wrote, it looks to be the case for a scalar f.
if I input
syms y(x) f(x)
I get this
sol =
exp(int(f(x) + 1, x, 'IgnoreSpecialCases', true, 'IgnoreAnalyticConstraints', true))/(C6 - int(-exp(int(f(x) + 1, x, 'IgnoreSpecialCases', true, 'IgnoreAnalyticConstraints', true)), x, 'IgnoreSpecialCases', true, 'IgnoreAnalyticConstraints', true))
that I don't understand clearly. I wonder if you can hel me again, please.
Thanks
Patrizio
Ameer Hamza
2020 年 6 月 14 日
I get your point. Yes, tspan plays the role of 'x'. Even if f is a function of 'x', you can consider that in the above code, f(x)=1, i.e., it is a constant function. Although, I agree with your point that in the general case, f and y need to vary with 'x'. Do you have a specific expression for f(x)? Solving it using dsolve() for general case f(x) might not give any useful results.
PatrizioGraziosi
2020 年 6 月 14 日
Hi Ameer, thanks!
Unfortunately f(x) is an experimental measurements and I don't have a precise analytical expression for it. I would need of y(x) to fit it and disentangle between two physical possibilities...
Anyway, I'l keep thinking about.
Ameer Hamza
2020 年 6 月 14 日
編集済み: Ameer Hamza
2020 年 6 月 14 日
If f is a function of 'x' but obtained experimentally, then you can use the solution in my answer by considering 'f' as a symbolic variable. Following shows how it can be done
syms y(x) f
eq = diff(log(y), x) + y == 1 + f;
sol = dsolve(eq);
odeFun = matlabFunction(odeToVectorField(eq), 'Vars', {'t', 'Y', 'f'});
xspan = 0:0.1:10; % time span for numerical solution
ic = 1; % initial condition: y(0)==1
fv = rand(size(xspan));
ffun = @(x) interp1(xspan, fv, x);
[x, y] = ode45(@(x, y) odeFun(t, y, ffun(x)), xspan, ic);
plot(x, y);
Here I used xspan as a vector, and the values of function f (fv) are also available for the values in xspan. I generated fv randomly in this code.

PatrizioGraziosi
2020 年 6 月 15 日
Thank you so much!!!
It will take to me a few days to test it, I'll keep you posted.
PatrizioGraziosi
2020 年 6 月 16 日
Hi Ameer,
you're solution is brilliant!
Sorry that I couldn't test it before... Your support has been excellent!
In the case we publish the data analysis done thanks to your solution, we'll aknowledge your support.
Thanks
Patrizio
Ameer Hamza
2020 年 6 月 17 日
I am glad that it worked for your case, and you got the results. Good luck with your research.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Symbolic Math Toolbox についてさらに検索
製品
参考
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)
