Plotting General Solution Of Differential Equation
이전 댓글 표시
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개)
Maybe
sol = dsolve(eq);
sols = subs(sol,[C1,C2,C3,C4],[-1,-1,-1,-1]);
fplot(sols,[-10,10])
댓글 수: 2
Fahad Ramzan
2021년 5월 23일
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.
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
Torsten
2021년 5월 23일
Is this logical ? Since Matlab introduces C1 - C4, it should be clear for the program that they are symbolic.
Fahad Ramzan
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
2021년 5월 23일
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!