symbolic integrate and plot a function of one variable

조회 수: 37 (최근 30일)
Val
Val 2025년 12월 9일 18:13
댓글: Val 2025년 12월 10일 9:50
Dear Hello
I apologize if there are any inaccuracies in the question.
I'm having a problem integrating a differential equation in a single variable.
The following is the differential equation satisfied by the function "x(u)" that is the x-component of a 2D curve given in parametric form (...this curve is the pathline of an infinitesimal volume of fluid, but that doesn't matter). The parameter "u" is time.
So pathline = {x(u), y(u)} is a 2D curve for 'u' in a certain interval.
Equation:
diff( x(u),u ) == 159648450049389632/(3991211251234741*(4 - (C1 + 2*u + 3)^(1/2))^(1/2)) - 8*x(u) + 14
C1 is a parameter that I'd like to keep,
and I look for a solution in the interval of 'u' in which the above expression is real.
I proceed by doing
dsolve( diff( x(u),u ) == 159648450049389632/(3991211251234741*(4 - (C1 + 2*u + 3)^(1/2))^(1/2)) - 8*x(u) + 14)
I get x(u) like this:
x(u) = exp(-8*u)*int(14*exp(8*u) + (159648450049389632*exp(8*u))/(3991211251234741*(4 - (C1 + 2*u + 3)^(1/2))^(1/2)), u, 'IgnoreSpecialCases', true, 'IgnoreAnalyticConstraints', true) + C2*exp(-8*u)
unless I've made a mistake somewhere.
I already had the 'y(u)' component of the pathline as a function of 'u', and it's:
y(u) = -1/(C1 + 2*u)
Now I'd like to visualize this pathline. To do this, I'll first set the two integration constants C1 and C2, e.g. C1=-3 and C2=1,
C1=-3
C2=1
x=eval(x)
y=eval(y)
now both x and y depend only on 'u', so I use the command
fplot(x,y)
but I get an error... I was wondering how to create this graph
thankYou very much !
Val
  댓글 수: 1
Walter Roberson
Walter Roberson 2025년 12월 9일 18:39
syms x(u) y(u) C1 C2
RHS = 159648450049389632/(3991211251234741*(4 - (C1 + 2*u + 3)^(1/2))^(1/2)) - 8*x(u) + 14;
LHS = diff(x,u);
eqn = LHS == RHS
eqn(u) = 
X(u) = dsolve(eqn)
X(u) = 
y(u) = -1/(C1 + 2*u)
y(u) = 
C1 = sym(-3)
C1 = 
C2 = sym(1)
C2 = 
1
X1 = subs(X)
X1(u) = 
Y1 = subs(y)
Y1(u) = 
fplot(X1);
Warning: Error in state of SceneNode.
First argument must be an integral 'int(..., ...)'.
Error using mupadengine/evalin2sym
First argument must be an integral 'int(..., ...)'.

Error in mupadengine/feval2sym_NaNsingularity

Error in matlab.graphics.function.internal.sym2fn (line 32)
f2 = feval2sym_NaNsingularity(symengine,'symobj::unapplyPlotFunction',sf,var_f);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in matlab.graphics.function.FunctionLine>getFunction

Error in matlab.graphics.function.FunctionLine/updateFunction

Error in matlab.graphics.function.FunctionLine

Error in fplot>singleFplot (line 268)
hObj = matlab.graphics.function.FunctionLine(fn{1},extraOpts{:},args{:});
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 223)
hObj = cellfun(@(f) singleFplot(cax,{f},limits,extraOpts,args),fn{1},'UniformOutput',false);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in fplot>vectorizeFplot (line 223)
hObj = cellfun(@(f) singleFplot(cax,{f},limits,extraOpts,args),fn{1},'UniformOutput',false);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in fplot (line 186)
hObj = vectorizeFplot(cax,fn,limits,extraOpts,args);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
hold on
fplot(Y1)
hold off

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

채택된 답변

Torsten
Torsten 2025년 12월 9일 20:19
편집: Torsten 2025년 12월 9일 20:20
syms x(u) y(u) g(u) C1 C2 v uref
g(u) = 159648450049389632/(3991211251234741*(4 - (C1 + 2*u + 3)^(1/2))^(1/2)) + 14;
x = C2*exp(-8*u)+exp(-8*u)*int(exp(8*v)*g(v),v,uref,u);
xs = subs(x,[C1 C2 uref],[-3 1 0]); % x satisfies x(uref) = C2*exp(-8*uref), thus here x(0) = C2
y = -1/(C1 + 2*u);
ys = subs(y,C1,-3);
fplot(xs,ys,[0 1])
  댓글 수: 2
Val
Val 2025년 12월 10일 9:34
thankyou Mr Torsten , transforming the indefinite integral to definite integral ---> fplot work ! very powerful plot command
You chose uref = '0' for some reason ?
Hello
Valerio
Val
Val 2025년 12월 10일 9:50
sorry , i saw just now , " % x satisfies x(uref) = C2*exp(-8*uref), thus here x(0) = C2 " thanks 😊

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2025년 12월 9일 18:47
The basic problem is that the integral that is produced by dsolve() is an indefinite integral, not a definite integral. That works out in theory, but fplot has trouble with it.
  댓글 수: 2
Val
Val 2025년 12월 10일 9:12
Ok , i need to transform it to a definite integral...thankyou very much 😊
Val
Val 2025년 12월 10일 9:44
Dear Mr Roberson
there exist an interpreter that transform expression written in matlab language to
expression with mathematical symbols like You done ?
"
"

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

카테고리

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

태그

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by