Solve the ODE and plot the graph as y=f(x). Also plot the derivative. 5. dy/dx=x*y
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Steven Lord
2021-7-21
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.
回答(1 个)
Shubham Khatri
2021-7-28
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!