Solving symbolic function in matlab
3 ビュー (過去 30 日間)
古いコメントを表示
Hi everyone,
I'm trying to use "solve" function to get an equation for two variables(t,VX), code is here. "CL,VG,VD,KN,VTH" are all constants. However, matlab is always "busy" after it starts to work on this function. Did I do something wrong?
% t= int(CL/(KN*((VG-VX-VTH)*(VD-VX)-1/2*(VD-VX).^2)),0,VX), this is the
% original function
syms CL VG VD KN VX VTH t
func= CL/(KN*((VG-VX-VTH)*(VD-VX)-1/2*(VD-VX).^2))
sol=solve(t==int(func,0,VX),VX,t)
2 件のコメント
John D'Errico
2022 年 2 月 4 日
編集済み: John D'Errico
2022 年 2 月 4 日
syms CL VG VD KN VX VTH t
func = CL/(KN*((VG-VX-VTH)*(VD-VX)-1/2*(VD-VX).^2))
Now you want to integrate func, from 0 to VX? What is the variable of integration? Surely not VX? Are you hoping that INT will in some way know which variable to integrate that expression over?
回答 (1 件)
John D'Errico
2022 年 2 月 4 日
編集済み: John D'Errico
2022 年 2 月 4 日
So VX is both a variable of integration, AND the upper limit for the integral? Seriously? Do you accept that this is the sort of thing that will confuse the hell out of a computer? How will it guess which variable to integrate on? That will cause bugs in your code, when you are yourself confused trying to debug your code? I'm a mathematician, and it certainly confused me trying to guess what the variable of integration was.
Has MATLAB started charging extra if we create a new variable and they never told me? Is there now a limit on the number of variable names? You can do something as simple as this:
syms CL VG VD KN VX VTH t vx
func = CL/(KN*((VG-vx-VTH)*(VD-vx)-1/2*(VD-vx).^2))
So now I'll tell MATLAB the variable of integration is vx, in lower case. I guess I'll see a bill on my credit card for doing that. Such is life. But now I've told MATLAB what to integrate on. First, can it perform the integration at all? CHECK THESE THINGS BEFORE YOU JUST THROW IT INTO SOLVE, AND HOPE IT GIVES YOU SOMETHING VIABLE.
int(func,vx,0,VX)
It took a few seconds, but it tried to find an analytical solution. But did it really find a solution? In fact, I see a mess of stuff, that includes the integral itself we just said to perform. So in fact, MATLAB pretty much gave up on that quest. And that means the solve will be a waste of time. In fact, It will probably just sit there and do its very best to melt down the CPU of your computer while trying. They told me to do WHAT? Sometimes computers can be such suicidal things. I know mine has frequently tried to melt itself into a pile of slag on the problems I tell it to solve. :)
Seriously, if those unknown constants have real values that you know, then substitute them. MATLAB should be able to perform a partial fractions decomposition then, and now the integral will one hopes be viable. But a problem is where those singularities lie. For some values of those constants, the integral may not exist at all.
1 件のコメント
Paul
2022 年 2 月 4 日
Interestsingly enough, the symbolic math toolbox seems to be a bit loose when it comes to the variable of integration and the limits of integration. For example, define a function v(t)
syms v(t)
v(t) = t^2;
Normally, if one wants to integrate v(t) to another function of t where t is the upper limit of integration, I think it would be done this way
syms tau
p(t) = int(v(tau),tau,0,t)
But Matlab seems to be perfectly happy with
int(v(t),t,0,t)
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



