Solve the ODE and plot the graph as y=f(x). Also plot the derivative. 5. dy/dx=x*y
    7 views (last 30 days)
  
       Show older comments
    
syms y(x)
D=diff(y,x)==x*y;
A=x*y
C=y(0)==0;
S=dsolve(D,C)
grid on 
hold on 
fplot(x,S,'r-','linewidth',3)
fplot(x,A,'b-','linewidth',3)
Warning: Error updating ParameterizedFunctionLine.
 The following error was reported evaluating the function in FunctionLine update: Unable to convert expression containing remaining symbolic function
 calls into double array. Argument must be expression that evaluates to number.
1 Comment
  Steven Lord
    
      
 on 21 Jul 2021
				This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
Answers (1)
  Shubham Khatri
    
 on 28 Jul 2021
        Hello
To my understanding, we know that S is a function of x. We need not specify x in fplot, rather we can directly use S to plot the function. Please take a look at the code below. As an extra step, i have specified the min and max interval values of x for the plot. For more information, please take a look at the documentation of fplot.
clc 
clear all
syms y(x)
D=diff(y)==x*y;
A=x*y
C=y(0)==2;
S=dsolve(D,C)
grid on 
hold on 
xmin=-5;
xmax= 5;
fplot(S,[xmin,xmax],'r-','linewidth',3)
fplot(S,[xmin,xmax],'b-','linewidth',3)
Hope it helps
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

