Plotting General Solution Of Differential Equation
조회 수: 4 (최근 30일)
이전 댓글 표시
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])
댓글 수: 0
답변 (2개)
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
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
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
% 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])
댓글 수: 4
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.
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!