I want to write a script that reads an input text file that specifies the parameters and then uses them to solve an integral
Show older comments
I want to write a script that reads an input text file that specifies the parameters:
a:1
b:2
c:3
d:4
x0:1
y0:1
tf:25.
Then integrate a system of equations given the parameters read from the input text file. Sytem should be integrated from t=0 to t=tf. After plot x(t) and y(t) in a single graph.

This is what I did. It gives me errors. Kindly tell me what i am doing wrong and how to solve the question. Thanks.
[q,w] = readvars('variables.txt');
a = w(1);
b = w(2);
c = w(3);
d = w(4);
x0 = w(5);
y0 = w(6);
tf = w(7);
t = 0;
x = linspace(t,tf,25);
fx = @(x,y) a*x-b*x*y;
fy = @(y,x) c*x*y-d*y;
x = linspace(t,tf,25);
for i = 1:length(x)
fx(i)= integral(@(x)(fx(x,y)),t,x(i));
end
y = linspace(t,tf,25);
for k = 1:length(y)
fy(k)= integral(@(y)(fy(y,x)),t,y(k));
end
figure (1)
plot(fx)
plot(fy)

3 Comments
Torsten
on 14 Dec 2022
I can only repeat: you can't use "integral" to solve differential equations that depend in the dependent variable.
You must use one of the ode integrators or try "dsolve".
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
