Solving an equation with integration constants and boundary conditions

18 ビュー (過去 30 日間)
Richard
Richard 2021 年 11 月 27 日
編集済み: Paul 2021 年 11 月 27 日
I have issues with solving an equation with integration constants and boundary conditions.
In this case the equation is presented in the image below, where I calculated the problem by my hand and I would like to replicate a similar solution, where I get as a symfun depending on r, and then using vpa to get a numerical value for a specific r, .
Boundary conditiions:
I was aiming to write in manner as follows, but the result is not what I expected:
r1 = 10;
r2 = 20;
syms A B p2
eqn = [A-B/(r1^2)==0, A-B/(r2^2)==-p2];
Sol_A = solve(eqn,A)
Sol_B = solve(eqn,B)
It is clear that in the code above, the integration constants A, B are firstly solved so that they can be substituted into function . I would prefer to get directly in order to obtain an algorithm to use in other different problems, where the "solving by hand" is not so straightforward.
Thank you in advance

採用された回答

Paul
Paul 2021 年 11 月 27 日
編集済み: Paul 2021 年 11 月 27 日
syms sigma_r(r) A B p_2 r1 r2
sigma_r = A - B/r^2
sigma_r = 
% eqn = sigma_r == 0; % edit: commented out after posting original answer. Not used.
%r1 = 10; r2 = 20; % uncomment this line to get the solution directly
cond1 = subs(sigma_r,r,r1) == 0;
cond2 = subs(sigma_r,r,r2) == -p_2;
solAB = solve([cond1 cond2],[A B])
solAB = struct with fields:
A: (p_2*r2^2)/(r1^2 - r2^2) B: (p_2*r1^2*r2^2)/(r1^2 - r2^2)
sigma_r = subs(sigma_r,[A B],[solAB.A solAB.B])
sigma_r = 
sigma_r = subs(sigma_r,[r1 r2],[10 20])
sigma_r = 
  2 件のコメント
Richard
Richard 2021 年 11 月 27 日
編集済み: Richard 2021 年 11 月 27 日
I really thank you for the effort. I am not a real expert in this branch, so I got stuck. By the way if I am not mistaken eqn = sigma_r == 0; is useless in this case.
Thank you again!
Paul
Paul 2021 年 11 月 27 日
You're not mistaken. I had defined eqn before I fully understood the question and then did not delete. I'll edit the post.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFormula Manipulation and Simplification についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by