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

3 ビュー (過去 30 日間)
% 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;
double(P(t));
%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
x=0:0.2:30;
y=double(Psoln(x));
Title = "Growth Problem";
XValue = "Days";
YValue = "Number of Insects";
plot(x,y,'b--');
hold on;
title(Title);
xlabel(XValue);
ylabel(YValue);
plot(0,Psoln(0),'r*');
plot(24,Psoln(24),'r*');
hold off;
  2 件のコメント
Christella Bañaga
Christella Bañaga 2021 年 10 月 29 日
The Differential Equation Model 0% (10%)
Variable eqn1 must be of data type symfun. It is currently of type sym. Check where the variable is assigned a value.
Assessment result: incorrectIs the model for condition 1 properly set? 0% (10%)
Variable k1 must be of data type sym. It is currently of type symfun. Check where the variable is assigned a value.
Assessment result: incorrectIs the model for condition 1 properly set? 0% (10%)
Variable k2 must be of data type sym. It is currently of type symfun. Check where the variable is assigned a value.
the above statement are my errors
Walter Roberson
Walter Roberson 2021 年 11 月 8 日
Change
eqn1 = dP-k*P==0;
to
eqn1 = dP-k*P;
Change
k1(t,k) = dsolve(eqn1,cond1);
k2(t,k) = dsolve(eqn1,cond2);
to
k1 = dsolve(eqn1,cond1);
k2 = dsolve(eqn1,cond2);
And later instead of using k1 and k2 with parameters, subs() values for variables.

サインインしてコメントする。

回答 (1 件)

Gargi Patil
Gargi Patil 2021 年 11 月 8 日
編集済み: Gargi Patil 2021 年 11 月 8 日
Hi,
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.

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by