【发布时间】:2019-01-19 00:10:37
【问题描述】:
给定一个矩阵形式的微分方程:
f = @(t,y) [(a*y(1) + b*y(2)); (c*y(1) + d*y(2))];
a=-2; b=-1; c=1; d=-4
我的微分方程问题的解决方案是
x(t)= e^(-3t) (t+1)
y{t)= e^(-3t) *t
一般解决方案是
Y(t)= e^(-3t) (xo,yo)' + t * e^(-3t) (xo-yo,xo-yo)'
初始条件为 (xo,yo)=(1,0)=(e;g)
Matlab 代码:
syms xSol ySol ran with and without this statement with same error msg
t=-1.1:0.1:2.1;
plot(t,xSol) error occurs here
hold on
plot(t,ySol)
hold off
错误信息:
Error using plot
Data must be numeric, datetime, duration or an array convertible to double.
进一步研究表明 xSol 和 ySol 必须是数字。 我有初始条件 (1;0);
xSol(t) = exp(-3*t) + t*exp(-3*t)
ySol(t) = t*exp(-3*t)
我需要将 xSol(t) 和 ySol(t) 更改为没有 (t) 的 xSol 和 ySol。 怎么修?更正必须使用复数。
在线示例使用fplot。这是在此应用程序中使用的更好功能吗? 我需要为 xSolv 和 ySolv 定义两个函数。我的代码适用于两个变量的通用微分方程。
网上的例子是
f = @(x) sin(1/x);
假设我们想要在 0.01 和 1 之间绘制它:
lims = [.01 1];
fplot(f, lims, '.-')
我试过了
xSolvpa = vpa(xSol)
ySolvpa = vpa(ySol)
fplot(xSolvpa,[-2.1 1.5])
hold on
fplot(t,ySolvpa,[-2.1 1.5])
但情节错误。这令人不安。没有给出错误。
怎么办?
MM
【问题讨论】:
标签: matlab plot types matlab-coder