set first derivative equal to zero with some constant

15 ビュー (過去 30 日間)
nirwana
nirwana 2023 年 5 月 14 日
編集済み: Torsten 2023 年 5 月 14 日
I have equation from derive from snellius law and i'd like to set its derivative equal to zero since fermat principle said so.
here the matlab that I used to get fist derivative, but when I solve it in order to get x value when dT/dt=0 it give me strange result. Is it because I put a lot of variable in syms? actually a, b, c, v1 and v2 is a constant. should I put it a number rather than a alphabet symbol to get proper result?
syms x a b c v1 v2
T=sqrt(x.^2+a^2)./v1+sqrt((b-x).^2+c^2)./v2;
dTdx=diff(T)
dTdx = 
fermat=solve(dTdx==0,x)
fermat = 
  2 件のコメント
Matt J
Matt J 2023 年 5 月 14 日
編集済み: Matt J 2023 年 5 月 14 日
but when I solve it in order to get x value when dT/dt=0 it give me strange result.
What's the result, and what is strange about it?
Dyuman Joshi
Dyuman Joshi 2023 年 5 月 14 日
What are you solving with dTdx == 0 is a polynomial in x, and thus you are getting the roots of the polynomial as the output, in terms of the variables.
"actually a, b, c, v1 and v2 is a constant. should I put it a number rather than a alphabet symbol to get proper result?"
Yes. If you want Numerical solution, you will have to define the variables with numerical values.
Use double() if you want to convert the symbolic result into numerical result

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

回答 (1 件)

Matt J
Matt J 2023 年 5 月 14 日
編集済み: Matt J 2023 年 5 月 14 日
should I put it a number rather than a alphabet symbol to get proper result?
You should just use fzero The symbolic solutions for x are very messy.
[a, b, c, v1, v2]=deal(1);
fun=@(x) x./sqrt(x.^2+a.^2)./v1 -(b-x)./sqrt((b-x).^2+c.^2)./v2;
x = fzero(fun,1)
x = 0.5000
fplot(fun,[-5 ,5]); yline(0); xline(x)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by