call dsolve() equation as function for reference.

조회 수: 3 (최근 30일)
jg
jg 2020년 1월 20일
답변: Star Strider 2020년 1월 20일
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?

채택된 답변

Star Strider
Star Strider 2020년 1월 20일
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.

추가 답변 (0개)

카테고리

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