Why does it say f plot error line 97

조회 수: 10 (최근 30일)
Maria De Silva
Maria De Silva 2017년 5월 14일
댓글: Star Strider 2017년 5월 14일
I have the equation from ysol is 3*cos(2*x) - 3*exp(-3*x) - 2*sin(2*x) however whenever i plot it using fplot it gives me an error Index exceeds matrix dimensions.
Error in fplot (line 97) xmin = min(lims(1:2)); xmax = max(lims(1:2));
Heres my codes
ySol(x) = dsolve(ode,conds)
ySol = simplify(ySol);
x = 0.0:1.:30.0;
figure
fplot(ySol,'r',[0 30])

답변 (1개)

Star Strider
Star Strider 2017년 5월 14일
Since ‘x’ is the independent variable in your equation, do not define it as a vector if you want to use the fplot function. Leave it undefined, and fplot will implicitly consider ‘ySol’ as a single-variable function.
This works:
ySol = 3*cos(2*x) - 3*exp(-3*x) - 2*sin(2*x);
figure
fplot(ySol,'r',[0 30])
  댓글 수: 4
Maria De Silva
Maria De Silva 2017년 5월 14일
편집: Star Strider 2017년 5월 14일
syms y(x)
Dy = diff(y);
Dy2= diff(y,2);
ode = diff(y,x,3)+3*diff(y,x,2)+4*diff(y,x,1)+12*y == 0;
cond1 = y(0) == 0;
cond2 = Dy(0) == 5;
cond3 = Dy2(0) == -39;
conds = [cond1 cond2 cond3];
ySol(x) = dsolve(ode,conds);
ySol = simplify(ySol)
figure
fplot(ySol,'r',[0 30])
title(' Homogeneous linear ODE, complex roots, IVP')
legend('3*cos(2*x) - 3*exp(-3*x) - 2*sin(2*x)')
Here is everything
Star Strider
Star Strider 2017년 5월 14일
Your code as you posted it works perfectly for me and produces this plot (in R2017a):

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by