Solving symbolic function in matlab

조회 수: 3 (최근 30일)
Holz
Holz 2022년 2월 4일
댓글: Paul 2022년 2월 4일
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
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))
func = 
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?
Holz
Holz 2022년 2월 4일
Hi John,
thanks for your answer. Here is the original function I want to solve:
If I change "sol" into following code, is it right? "VX" is the only variable of integration.
sol=solve(t==int(func,VX,0,VX),VX,t)

댓글을 달려면 로그인하십시오.

답변 (1개)

John D'Errico
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))
func = 
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)
ans = 
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
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)
p(t) = 
But Matlab seems to be perfectly happy with
int(v(t),t,0,t)
ans = 

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by