フィルターのクリア

Plotting General Solution Of Differential Equation

4 ビュー (過去 30 日間)
Fahad Ramzan
Fahad Ramzan 2021 年 5 月 23 日
編集済み: Paul 2021 年 5 月 23 日
It's Giving Many Errors and not plotting the graph. Am unable to indentfy what to do next. The error are as following
Error using fplot>singleFplot (line 227)
Input must be a function or functions of a single variable.
Error in fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 191)
hObj = cellfun(@(f) singleFplot(cax,{f},limits,extraOpts,args),fn{1},'UniformOutput',false);
Error in fplot>vectorizeFplot (line 191)
hObj = cellfun(@(f) singleFplot(cax,{f},limits,extraOpts,args),fn{1},'UniformOutput',false);
Error in fplot (line 161)
hObj = vectorizeFplot(cax,fn,limits,extraOpts,args);
Error in Untitled (line 15)
fplot(sol,[-10 10])
clc
clear all
syms y(x)
D4y = diff(y,4)
D3y = diff(y,3)
D2y = diff(y,2)
Dy = diff(y)
eq= D4y +(2.*D3y)+(11.*D2y)+(2.*Dy)+(10.*y)
sol = dsolve(eq)
C1=-1
C2=-1
C3=-1
C4=-1
fplot(sol,[-10 10])

回答 (2 件)

Torsten
Torsten 2021 年 5 月 23 日
編集済み: Torsten 2021 年 5 月 23 日
Maybe
sol = dsolve(eq);
sols = subs(sol,[C1,C2,C3,C4],[-1,-1,-1,-1]);
fplot(sols,[-10,10])
  2 件のコメント
Fahad Ramzan
Fahad Ramzan 2021 年 5 月 23 日
am getting the error Undefined function or variable 'C1'.
Torsten
Torsten 2021 年 5 月 23 日
If you apparently can't set the free parameters of the solution directly (they are named C1,C2,C3 and C4 from Matlab, I guess), you will have to specify 4 boundary conditions in order to get a unique solution that can be plotted. Use the "cond" command to do this.

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


Paul
Paul 2021 年 5 月 23 日
Need to add one line of code
syms y(x)
D4y = diff(y,4);
D3y = diff(y,3);
D2y = diff(y,2);
Dy = diff(y);
eq= D4y +(2.*D3y)+(11.*D2y)+(2.*Dy)+(10.*y) == 0;
sol = dsolve(eq) % homogeneous solution
sol = 
% need to define Ci as sym objects before using subs()
syms C1 C2 C3 C4
% now substitute
sol = subs(sol,[C1 C2 C3 C4],[-1 -1 -1 -1])
sol = 
  4 件のコメント
Paul
Paul 2021 年 5 月 23 日
編集済み: Paul 2021 年 5 月 23 日
Don't know if it's logical. But I think it works this way because Matlab keeps track of these constants over the course of a session and keeps "incrementing" them. For example, I started a fresh Matlab session on my computer:
syms y(x)
D4y = diff(y,4);
D3y = diff(y,3);
D2y = diff(y,2);
Dy = diff(y);
eq = D4y +(2.*D3y)+(11.*D2y)+(2.*Dy)+(10.*y) == 0;
sol = dsolve(eq) % homogeneous solution
sol =
C5*cos(x) - C6*sin(x) + C3*cos(3*x)*exp(-x) - C4*sin(3*x)*exp(-x)
>> sol = dsolve(2*lhs(eq)==0) % homogeneous solution, sort of different equation
sol =
C9*cos(x) - C10*sin(x) + C7*cos(3*x)*exp(-x) - C8*sin(3*x)*exp(-x)
If the constants were actually poofed as new variables into the workspace, then user variables could be overwritten or Matlab would have to interrogate the workspace to find non-conflicting names.
In this particular case, I have no idea why the first instance of sol used C3-C6 instead of C1-C4. Very mysterious.
I can't find anything in the doc that explains how to "reset" the constants so they start at C1.
Fahad Ramzan
Fahad Ramzan 2021 年 5 月 23 日
Hmm

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

カテゴリ

Help Center および File ExchangeNumeric Solvers についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by