My question is very simple, my function has values for x,y,t but only displays values for x. I want the values of y and t to also be returned.
function [x, y, t] = IVP(c)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
syms x y h t;
h=c;
x=zeros(1,30);
y=zeros(1,30);
u=[2;1];
t=[0:1:29];
for i=2:1:30
x(1)=2;
y(1)=1;
x(i)=u(1)+h*(1.2*u(1)-0.6*u(1)*u(2));
y(i)=u(2)+h*(0.3*u(1)*u(2)-0.8*u(2));
u(1)=x(i);
u(2)=y(i);
end
plot(t,x,'b',t,y,'k');
xlabel('time') % x-axis label
ylabel('Population of Prey and Predator') % y-axis label
legend('x(t)-prey','y(t)-predator')
end

2 commentaires

Nagarjun Vinukonda
Nagarjun Vinukonda le 25 Oct 2020
Modifié(e) : Nagarjun Vinukonda le 25 Oct 2020
I was having the same trouble, it is because before the function you are not calling variables properly. You should call the function as provided in answer.
Joe Payne
Joe Payne le 28 Fév 2022
Is that eulers method for solving the preditor pray system of 2 first order ODEs. Cus I'm doing a project on solving the preditor prey equation. If you are too what books/websites would you recommend?

Connectez-vous pour commenter.

 Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 26 Mar 2016

22 votes

Call the function like this
[x, y, t] = IVP(c)

5 commentaires

Tamoghna Bhattacharya
Tamoghna Bhattacharya le 25 Jan 2019
Can vectors and matrices be passed as output arguments?
Vidar Haugen
Vidar Haugen le 28 Jan 2019
yes.
shaik Asif hussain
shaik Asif hussain le 28 Fév 2019
how can i return those changed values to x,y,t to function
so that i can use them in comm prompt
Redouane Bouchou
Redouane Bouchou le 8 Avr 2020
Thank you
Amir Chamanara
Amir Chamanara le 19 Avr 2020
Thanks.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by