where is the error
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
0 投票
I want to know where is the error please
% Symbolic
syms x(t) y(t) z(t) p k a1 a2 b2 c d sigma beta
Eqn1 = diff(x(t), t) == p*x*(1-y/k)-a1*x*y;
Eqn2 = diff(y(t), t) == c*a1*x*y-d*y-a2*y*z/(y+a2);
Eqn3 = diff(z(t), t) == sigma*z^2-beta*z^2/(y+b2);
Sols = dsolve([Eqn1, Eqn2, Eqn3])
Warning: Unable to find symbolic solution.
S= dsolve([Eqn1, Eqn2, Eqn3])
Sols
[xSol(t),ySol(t),zSol(t)] = dsolve(Eqns)
(2) Numerical Solution - see DOC:
%% Numerical solutions
ICs = [pi; pi/2; 2]; % Initial Conditions
[time, Sol]=ode45(@(t, xyz)FCN(t, xyz), [0, 10], ICs);
plot(time, Sol(:,1), 'r',time, Sol(:,2), 'g', time, Sol(:,3), 'b', 'linewidth', 2)
legend('x(t)', 'y(t)', 'z(t)'); grid on
title('Numerical Solutions')
xlabel('$t$', 'interpreter', 'latex')
ylabel('$x(t), \ y(t), \ z(t)$', 'interpreter', 'latex')
function dxyz = FCN(t, xyz)
p =.1;
k =.2;
a1 =.3;
a2 =.4;
b2 =.5;
c =.6;
d =.7;
sigma =.8;
beta =.9;
dxyz=[p*xyz(1)*(1-xyz(2)/k)-a1*xyz(1).*xyz(2);
c*a1*xyz(1).*xyz(2)-d*xyz(2)-a2*xyz(2).*xyz(3)./(xyz(2)+a2);
sigma*xyz(3).^2-(beta*xyz(3).^2)./(xyz(2)+b2)];
end
Unrecognized function or variable 'There'.
>> 

採用された回答
Star Strider
2022 年 12 月 30 日
The system is nonlinear, and not one of the few nonlinear systems that haave analytic solutions.
After commenting-out the dsolve call, it appears to provide a solution —
% Symbolic
syms x(t) y(t) z(t) p k a1 a2 b2 c d sigma beta
Eqn1 = diff(x(t), t) == p*x*(1-y/k)-a1*x*y;
Eqn2 = diff(y(t), t) == c*a1*x*y-d*y-a2*y*z/(y+a2);
Eqn3 = diff(z(t), t) == sigma*z^2-beta*z^2/(y+b2);
Sols = dsolve([Eqn1, Eqn2, Eqn3])
Warning: Unable to find symbolic solution.
Sols =
[ empty sym ]
% Warning: Unable to find symbolic solution.
S= dsolve([Eqn1, Eqn2, Eqn3])
Warning: Unable to find symbolic solution.
S =
[ empty sym ]
Sols
Sols =
[ empty sym ]
% [xSol(t),ySol(t),zSol(t)] = dsolve(Eqns)
% (2) Numerical Solution - see DOC:
%% Numerical solutions
ICs = [pi; pi/2; 2]; % Initial Conditions
[time, Sol]=ode45(@(t, xyz)FCN(t, xyz), [0, 10], ICs);
plot(time, Sol(:,1), 'r',time, Sol(:,2), 'g', time, Sol(:,3), 'b', 'linewidth', 2)
legend('x(t)', 'y(t)', 'z(t)'); grid on
title('Numerical Solutions')
xlabel('$t$', 'interpreter', 'latex')
ylabel('$x(t), \ y(t), \ z(t)$', 'interpreter', 'latex')

function dxyz = FCN(t, xyz)
p =.1;
k =.2;
a1 =.3;
a2 =.4;
b2 =.5;
c =.6;
d =.7;
sigma =.8;
beta =.9;
dxyz=[p*xyz(1)*(1-xyz(2)/k)-a1*xyz(1).*xyz(2);
c*a1*xyz(1).*xyz(2)-d*xyz(2)-a2*xyz(2).*xyz(3)./(xyz(2)+a2);
sigma*xyz(3).^2-(beta*xyz(3).^2)./(xyz(2)+b2)];
end
.
12 件のコメント
Thank you so much
may i ask if i want to graph every equation alone with t time, what i have to put command?
Star Strider
2022 年 12 月 30 日
Example —
ICs = [pi; pi/2; 2]; % Initial Conditions
[time, Sol]=ode45(@(t, xyz)FCN(t, xyz), [0, 10], ICs);
ttlc = {'x(t)', 'y(t)', 'z(t)'};
cv = 'rgb';
NrSp = size(Sol,2);
for k = 1:NrSp
subplot(NrSp,1,k)
plot(time, Sol(:,k), cv(k), 'linewidth', 2)
grid on
ylim([0 3.5])
title(sprintf('Numerical Solutions: %s',ttlc{k}))
xlabel('$t$', 'interpreter', 'latex')
ylabel(sprintf('$%s$',ttlc{k}), 'interpreter', 'latex')
end

function dxyz = FCN(t, xyz)
p =.1;
k =.2;
a1 =.3;
a2 =.4;
b2 =.5;
c =.6;
d =.7;
sigma =.8;
beta =.9;
dxyz=[p*xyz(1)*(1-xyz(2)/k)-a1*xyz(1).*xyz(2);
c*a1*xyz(1).*xyz(2)-d*xyz(2)-a2*xyz(2).*xyz(3)./(xyz(2)+a2);
sigma*xyz(3).^2-(beta*xyz(3).^2)./(xyz(2)+b2)];
end
Make appropriate changes to get the result you want.
.
Ahmad
2022 年 12 月 30 日

I don't know why it kept give me error although i copy and paste only, i don't change anything
Star Strider
2022 年 12 月 30 日
Apparently, you still have the symbolic code in your script. It would be best to delete it, because there is no symbolic solution to most nonlinear differential equations, and yours are among those that do not have symbolic solutions.
okay thank you so much, i have been tried but doesn't work .and i approciate your helping, thank you again
Les Beckham
2022 年 12 月 30 日
You can't paste the code into the command window. It has to be in a file. In your original question it looks like you pasted code into the command window (note the >> prompt).
Open a new script in the editor. Paste the code into the editor (you can copy it by clicking the Copy button in the upper right of Star Strider's comment above) and save it as, for example, simFCN.m.
Then you can run it from the command line as follows:
>> simFCN
Or click the Run button in the editor.
Star Strider
2022 年 12 月 31 日
@Les Beckham — I agree. I saw this a few hours ago. I can’t add anything to your comment.
Ahmad
2022 年 12 月 31 日
Thank you so much @Les Beckham and @Star Strider, I really don't have any expriance with Matlab, although I woud like to learn it , anyhow i will keep trying learning it, thank you both of you for helping me .
Star Strider
2022 年 12 月 31 日
As always, our pleasure!
A very good way to learn is to read the threads on MATLAB Answers, as your time permits. I have learned much from reading how other people solve problems.
.
Les Beckham
2022 年 12 月 31 日
You are quite welcome.
I agree with Star Strider. Also, I would suggest taking some time to go through the online tutorial here:
Ahmad
2022 年 12 月 31 日
Happy new year to you, i hope that both of you will have a great 2023 and being happy with full of peaceful to both of you. also we wish that peace spread over all the worlds.
Star Strider
2022 年 12 月 31 日
Thank you!
And to you (and the world) as well!
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Numeric Solvers についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
