im having trouble with symfun here. it says that eqn1, k1, and k2 must be data of sym. how do i do that?

22 visualizzazioni (ultimi 30 giorni)
% Suppose a population of insect increases at a rate proportional to the amount present.
% There were 100 insects after the third day of the experiment and 250 insects after the seventh day.
% Approximately how many insects were in the original population? How many insects will there be after 24 days?
%Setup the variables P(t), k that will be used in the program. Find also the derivative of P(t) and set as dP
syms t k P(t);
dP = diff(P,t);
%Initial Conditions
cond1 = P(3)==100;
cond2 = P(7)==250;
%Set the differential equation model as eqn1;
eqn1 = dP-k*P==0;
P(t) = eqn1;
%Find k1 and k2, by solving the initial value problem eqn1 using cond1 and cond2, respectively.
k1(t,k) = dsolve(eqn1,cond1);
k2(t,k) = dsolve(eqn1,cond2);
%Solve for k by equating k1 and k2 at t=0. Save results as k.
Sol(k) = k1(0,k)-k2(0,k);
eqn1 = Sol(k)==0;
k = solve(eqn1);
%Solve the eqn1 using the acquired value of k and using Initial value cond1.
Psoln(t) = k1(t,k);
x = linspace(-1,25,100);
y = Psoln(x);
%Evaluate Psoln at t=0, save your answer as P0. Express your answer in decimals, save answer as Po.
P0 = subs(Psoln(0));
Po = round(P0,2);
Po = double(Po);
%Evaluate Psoln at t=24, save your answer as P24. Express your answer in decimals, save answer as Po24.
P24 = subs(Psoln(24));
Po24 = round(P24,2);
%Plot the equation
Title = "Growth Problem";
XValue = "Days";
YValue = "Number of Insects";
hold on;
hold off;
  2 Commenti
Walter Roberson
Walter Roberson il 8 Nov 2021
eqn1 = dP-k*P==0;
eqn1 = dP-k*P;
k1(t,k) = dsolve(eqn1,cond1);
k2(t,k) = dsolve(eqn1,cond2);
k1 = dsolve(eqn1,cond1);
k2 = dsolve(eqn1,cond2);
And later instead of using k1 and k2 with parameters, subs() values for variables.

Accedi per commentare.

Risposte (1)

Gargi Patil
Gargi Patil il 8 Nov 2021
Modificato: Gargi Patil il 8 Nov 2021
I'm unable to reproduce the error you are facing. The code provided in the question is running without errors in MATLAB R2021b and MATLAB Online.
Based on the error messages, the assesment grader expects k1 and k2 to store symbolic values rather than equations (dsolve returns a differential equation). Similarly, eqn1 is expected to be a symbolic equation. Kindly verify the solution you are providing to the grader as this isn't an error due to MATLAB compilation.

Community Treasure Hunt

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

Start Hunting!

Translated by