call dsolve() equation as function for reference.

1 view (last 30 days)
I have a dynamical system which i am implementing it does not always agree with what i am expecting because of random permutation. So i trying to use the diff function to give my system a nudge in the right direction when needed.
There for i have vreated this model below. when looking at what the returned equation is i get,
-1000/(51*(exp(log(97/102) - z/100) - 1))
how would i be able to insert the varable z to this equation with every itteration of a for loop? where the for loop argument is the point of time?
hold all;
clear all;
clc;
close all;
hold on
syms A(z)
B0 = 400;
N = 1000;
beta = 0.51;
gamma = 0.5;
Tend =100;
cond = A(0) == B0;
eqns = diff(A,z) == beta*(A/N)*(N-A)-gamma*A;
S = dsolve(eqns,cond);
fplot(S,[0 Tend],'y--','LineWidth',4)
a = S(1);
a(10)
I have modified the code getting a better result now but still cant figure this out.
hold all;
clear all;
clc;
close all;
hold on
syms A(z)
B0 = 400;
N = 1000;
beta = 0.51;
gamma = 0.5;
Tend =100;
cond = A(0) == B0;
eqns = diff(A,z) == beta*(A/N)*(N-A)-gamma*A;
S = dsolve(eqns,cond);
fplot(S,[0 Tend],'y--','LineWidth',4)
a(z) = S;
a(10)
a(10) now returns -1000/(51*(exp(log(97/102) - 1/10) - 1))
however i dont want the equation but rather the awnser how would i make this so that i get the solved awnser returned which would be 140.5405?

Accepted Answer

Star Strider
Star Strider on 20 Jan 2020
Try this:
syms A(z)
B0 = 400;
N = 1000;
beta = 0.51;
gamma = 0.5;
Tend =100;
cond = A(0) == B0;
eqns = diff(A,z) == beta*(A/N)*(N-A)-gamma*A;
S(z) = dsolve(eqns,cond);
fplot(S,[0 Tend],'y--','LineWidth',4)
a = S(1);
zv = sym(linspace(0,100,50)); % Create Vector
Azv = double(S(zv)) % Evaluate Integrated Differential Equation
I added two lines that may do what you want.

More Answers (0)

Categories

Find more on Particle & Nuclear Physics 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!