Solve the ODE and plot the graph as y=f(x). Also plot the derivative. 5. dy/dx=x*y

조회 수: 7 (최근 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
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
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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by