Plotting General Solution Of Differential Equation

31 views (last 30 days)
Fahad Ramzan
Fahad Ramzan on 23 May 2021
Edited: Paul on 23 May 2021
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])

Answers (2)

Torsten
Torsten on 23 May 2021
Edited: Torsten on 23 May 2021
Maybe
sol = dsolve(eq);
sols = subs(sol,[C1,C2,C3,C4],[-1,-1,-1,-1]);
fplot(sols,[-10,10])
  2 Comments
Torsten
Torsten on 23 May 2021
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.

Sign in to comment.


Paul
Paul on 23 May 2021
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 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!