Explicit solution could not be found.. > In dsolve at 194
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
here is my code :
>>sums u(t) v(t)
>>ode1= diff(u)==u^2/v - u
>>ode2= diff(v) == u^2-v
>>odes=[ode1;ode2]
採用された回答
Star Strider
2017 年 6 月 1 日
An analytic (symbolic) solution does not exist. You must us a numeric solver.
The Code —
syms T t u(t) v(t) u0 v0 Y
Du = diff(u);
Dv = diff(v);
ode1 = Du == u^2/v - u;
ode2 = Dv == u^2-v;
[ode_vf, ode_subs] = odeToVectorField(ode1,ode2);
ode_fcn = matlabFunction(ode_vf, 'vars',{T,Y});
tspan = linspace(0, 10, 150);
icv = [0; 0]+sqrt(eps);
[t,y] = ode45(ode_fcn, tspan, icv);
figure(1)
plot(t, y)
grid
23 件のコメント
This code doesn't work for me. The first line gives me a syntax error
I need to solve these differential equations :
du/dt = u^2/v - u dv/dt = u^2 - v
Can you please tell me a way of doing this ?
The code works in R2017a. Symbolic functions were introduced in R2012a. There is no work-around if you do not have that or a later release.
My pleasure. The results from the earlier computations are:
ode_vf =
Y[2]^2 - Y[1]
Y[2]^2/Y[1] - Y[2]
ode_subs =
v
u
ode_fcn =
function_handle with value:
@(T,Y)[Y(2).^2-Y(1);Y(2).^2./Y(1)-Y(2)]
In one line:
ode_fcn = @(T,Y) [Y(2).^2-Y(1);Y(2).^2./Y(1)-Y(2)];
You can then use that with this code to integrate your equations:
tspan = linspace(0, 10, 150);
icv = [0; 0]+sqrt(eps);
[t,y] = ode45(ode_fcn, tspan, icv);
figure(1)
plot(t, y)
grid
Note that in the plot, ‘u=Y(1)’ or the blue line, and ‘v=Y(2)’ or the red line.
Thanks a lot .. This solution is so elegant. I was using runge Kutta to solve this.. Thanks again
siddharth tripathi
2017 年 6 月 2 日
編集済み: Walter Roberson
2017 年 6 月 5 日
Hi . I just have one more doubt.
When i introduce parameters into my differential equation :
du/dt= a*u^2/v - b*u
dv/dt= c*u*u - d*v
There is no change in the plot even if i change them unconditionally.. is there no scope for parameters in this code ?
Thanks.
You need to go back and include them from the beginning.
The (Revised) Code —
syms a b c d T t u(t) v(t) u0 v0 Y
Du = diff(u);
Dv = diff(v);
ode1 = Du == a*u^2/v - b*u;
ode2 = Dv == c*u^2 - d*v;
[ode_vf, ode_subs] = odeToVectorField(ode1,ode2)
ode_fcn = matlabFunction(ode_vf, 'vars',{T,Y,a,b,c,d})
producing:
ode_vf =
c*Y[2]^2 - d*Y[1]
(a*Y[2]^2)/Y[1] - b*Y[2]
ode_subs =
v
u
ode_fcn =
function_handle with value:
@(T,Y,a,b,c,d)[-d.*Y(1)+c.*Y(2).^2;-b.*Y(2)+(a.*Y(2).^2)./Y(1)]
That will work. It requires that you change your ode45 call to:
[t,y] = ode45(@(T,Y) ode_fcn(T,Y,a,b,c,d), tspan, icv);
That should work.
This is not working !
I used the earlier code with the variables included! and then i defined the values of these parameters..
Will the solution be wrong if i dont do this modification that you have mentioned here ?
PS : error that i get is
[t,y] = ode45(@(T,Y) ode_fcn(T,Y,a,b,c,d), tspan, icv);
---------------------------------------------
Error using odearguments (line 113) Inputs must be floats, namely single or double.
Error in ode45 (line 115) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin)
You cannot use symbolic constants in the ode_fcn function.
This works:
ode_fcn = @(T,Y,a,b,c,d)[-d.*Y(1)+c.*Y(2).^2;-b.*Y(2)+(a.*Y(2).^2)./Y(1)];
a = 0.1;
b = 0.2;
c = 0.3;
d = 0.4;
tspan = [0 50];
icv = [1; 1];
[t,y] = ode45(@(T,Y) ode_fcn(T,Y,a,b,c,d), tspan, icv);
figure(1)
plot(t, y)
grid
xlabel('Time')
ylabel('Amplitude')
legend('u', 'v')
siddharth tripathi
2017 年 6 月 22 日
Hi Star. Thanks for all the help you provided.
Can you please let me know if i can do a fourier transform of the solution of this set of equation.. and how !
I will be much obliged.
My pleasure.
To do a Fourier transform of the results, ‘tspan’ must be a vector of times with a constant sampling time interval.
Try this:
ode_fcn = @(T,Y,a,b,c,d)[-d.*Y(1)+c.*Y(2).^2;-b.*Y(2)+(a.*Y(2).^2)./Y(1)];
a = 0.1;
b = 0.2;
c = 0.3;
d = 0.4;
L = 500;
tspan = linspace(0, 50, L);
icv = [1; 1];
[t,y] = ode45(@(T,Y) ode_fcn(T,Y,a,b,c,d), tspan, icv);
figure(1)
plot(t, y)
grid
xlabel('Time')
ylabel('Amplitude')
legend('u', 'v')
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nytquist Frequency
FTy = fft(y)/L; % Discrete Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
figure(2)
plot(Fv, abs(FTy(Iv))*2)
grid
Experiment with it to get the result you want.
I ll surely look into this and let you know if i receive what i wanted !
Star could you let me know the logic behind the use of the following and whatever these commands do :
[ode_vf, ode_subs] = odeToVectorField(ode1,ode2);
ode_fcn = matlabFunction(ode_vf, 'vars',{T,Y});
tspan = linspace(0, 10, 150);
icv = [0; 0]+sqrt(eps);
[t,y] = ode45(ode_fcn, tspan, icv);
siddharth tripathi
2017 年 6 月 23 日
And when you write ode_fcn you want me to write the snippet of code used above it as well right ??
This line:
[ode_vf, ode_subs] = odeToVectorField(ode1,ode2);
creates the symbolic vector field representation of the ODE function in ‘ode_vf’, and returns the substitutions the odeToVectorField made in ‘ode)_subs’, making it easier to interpret the results.
Then:
ode_fcn = matlabFunction(ode_vf, 'vars',{T,Y});
creates an anonymous function from ‘ode_vf’ and adds the time argument ‘T’ to the argument list as the numeric ODE solvers require.
The ‘tspan’ assignment creates the time vector for ode45, and icv are the initial conditions.
Finally:
[t,y] = ode45(ode_fcn, tspan, icv);
integrates the differential equation and produces the output.
I am not certain what you intend in your second comment. The code in this Comment (link) will run entirely on its own. You do not need anything else with it.
The ‘ode_fcn’ anonymous function was produced in the code in my original Answer (link). You do not need to re-derive it to use the code in my Comment.
siddharth tripathi
2017 年 6 月 23 日
Thanks a lot Star. I just was getting confused with the ode_vf and ode_subs thing. What do you use the icv for ?
siddharth tripathi
2017 年 6 月 23 日
You are the best Star. Never saw someone being so professionally helpful without any personal motives. I cannot thank you enough.
I must say i thoroughly understand non explicit solutions of differential equations because of you :)
Star Strider
2017 年 6 月 23 日
Thank you very much!
As always, my pleasure!
Why do you use :
sqrt (eps) ??
Star Strider
2017 年 6 月 24 日
Since eps is the smallest value (with respect to addition and subtraction) that can be represented numerically, it frequently goes to zero in some operations when used alone. Taking the square root first usually means that some small value survives calculations that square it, for example, so the result will not be zero. An alternative I also use is 1E-8, for the same reasons. It is simply a convention I have adopted for convenience.
I cannot explain why the results are so different when the input argument on the third variable in the function :
tspan = (0 , 500 ,200 )
makes so much of a difference. I mean when i use 500 instead of 200 the result is completely different. I cannot explain this !
siddharth tripathi
2017 年 6 月 24 日
Please can you clear this one doubt ???
You forgot to call the linspace function.
Try this:
tspan = linspace(0 ,500 ,200);
Hi star ! I hope you are doing good.
Can you please tell me how i can get graphs of u vs t and v vs t individually from this code ?
Thanks!
My pleasure.
Here you go:
syms T t u(t) v(t) u0 v0 Y
Du = diff(u);
Dv = diff(v);
ode1 = Du == u^2/v - u;
ode2 = Dv == u^2-v;
[ode_vf, ode_subs] = odeToVectorField(ode1,ode2);
ode_fcn = matlabFunction(ode_vf, 'vars',{T,Y});
tspan = linspace(0, 10, 250);
icv = [0; 0]+sqrt(eps);
[t,y] = ode45(ode_fcn, tspan, icv);
figure(1)
plot(t, y)
grid
lgndc = sym2cell(ode_subs); % Get Substituted Variables
lgnds = regexp(sprintf('%s\n', lgndc{:}), '\n','split'); % Create Cell Array
legend(lgnds(1:end-1), 'Location','NW', 'Location','NE') % Display Legend
figure(2)
subplot(2,1,1)
plot(t, y(:,1))
title([lgnds{1} '(t)'])
xlabel('\bft\rm')
ylabel('\bfAmplitude\rm')
subplot(2,1,2)
plot(t, y(:,2))
title([lgnds{2} '(t)'])
xlabel('\bft\rm')
ylabel('\bfAmplitude\rm')
その他の回答 (1 件)
Making the assumption that you made a minor typing mistake in entering your question, and that you are asking about
syms u(t) v(t)
ode1= diff(u)==u^2/v - u;
ode2= diff(v) == u^2-v;
odes = [ode1;ode2];
dsolve(odes)
then MATLAB is not able to provide analytic solutions. However, two analytic solutions exist:
1)
u(t) = 0
v(t) = C1 * exp(-t)
where C1 is an arbitrary constant whose value depends upon the initial conditions
2)
u(t) = RootOf(-Intat(-LambertW(-C1*exp(a_)/a_)/(a_*(LambertW(-C1*exp(a_)/a_)+1)), a_ = Z_) + t + C2)
v(t) = u(t)^2/(diff(u(t), t)+u(t))}
that ugly formula for u(t) says that there is a particular function involving a ratio of LambertW formulas, and that for any given t, u(t) is the value such that the integral of the ratio, evaluate at that value, is 0.
This is ugly. But it does provide a path to an analytic solution, of sorts. But it is beyond the capacity of MATLAB.
カテゴリ
ヘルプ センター および File Exchange で Ordinary Differential Equations についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
