Please Help Me! i want to plot a equation dx/dt = y-5; dy/dt = -x+5; x(0)=0,y(0)=0. What type of code solver should i use.

 Accepted Answer

syms x(t) y(t) %EDITED ANSWER
ode1=diff(x) == y-5;
ode2=diff(y)== -x+5;
[x,y]=dsolve(ode1,ode2,x(0)==0,y(0)==0)
fplot(subs(x),'r')
hold on
fplot(subs(y),'g')

9 Comments

if fplot doesn't work , try:
clear all
syms x(t) y(t)
ode1=diff(x) == y-5;
ode2=diff(y)== -x+5;
[x,y]=dsolve(ode1,ode2,x(0)==0,y(0)==0)
t=linspace(-2*pi,2*pi,1000)
x = subs(x,t)
y = subs(y,t)
plot(t,x,'r')
hold on
plot(t,y,'g')
Previous question has been wrong, please help me this: With dx/dt=y-5 , dy/dt=-x+5, x(0)=0, y(0)=0, draw the graph of y(x) !! Thanks so much !!
Previous question has been wrong, please help me this: With dx/dt=y-5 , dy/dt=-x+5, x(0)=0, y(0)=0, draw the graph of y(x) !! Thanks so much !!
y(x) what does it mean y is a function of x and x is a function of t?
Oh, both x and y are function of t !! and i need draw y(x)

Sign in to comment.

More Answers (2)

Use "dsolve" for solving and "fplot" for plotting.
Best wishes
Torsten.
So Sorry, The previous question has been wrong, please help me this: With dx/dt=y-5 , dy/dt=-x+5, x(0)=0, y(0)=0, draw the graph of y(x) !! Thanks so much !!

Products

Release

R2017a

Community Treasure Hunt

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

Start Hunting!