我想知道是否有人可以帮助我使用 MatLab 解决 Lotka-Volterra 方程。我的代码似乎不起作用。我执行以下操作:
第1步 -
我创建了一个名为 pred_prey_odes.m 的文件,其中包含以下代码:
% the purpose of this program is to model a predator prey relationship
% I will be using the Lotka-Volterra equations
% Program consists of the following differential equations:
% dY1/dt = a * Y1 - c * Y1 * Y2
% dY2/dt = b * Y2 - d * Y1 * Y2
function dy = pred_prey_odes(t, y)
% function that is to be integrated
%select constants
a = 1; …Run Code Online (Sandbox Code Playgroud) 我目前在PHP类示例中有以下__get/__ set方法:
class example{
/*Member variables*/
protected $a;
protected $b = array();
public function __get($name){
return $this->$name;
}
public function __set($name, $value){
$this->$name = $value;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,除了设置标准的受保护变量之外,我还希望能够在类中设置受保护的数组.我已经查看了一些其他问题,并找到了关于如何使用__get/__ set方法简单设置变量的一般建议,但没有任何允许使用这些魔术方法来设置BOTH数组和非数组的方法,即以下列方式:
$fun = new $example();
$fun->a = 'yay';
$fun->b['coolio'] = 'yay2';
Run Code Online (Sandbox Code Playgroud) 我制作了以下链表结构和printList函数.两者都正常运行:
struct Node{
int data;
Node *np;
};
void printList(Node *x){
cout << x->data << " ";
if (x->np != NULL){
printList(x->np);
}
return;
}
Run Code Online (Sandbox Code Playgroud)
然后我决定编写一个递归函数来复制链表.一个实现,返回指针值,工作...而另一个,返回一个地址 - 不起作用...我不能为我的生活弄清楚为什么会这样:
这有效:
Node * copyList(Node *x){
Node * y = new Node;
y->data = x->data;
if (x->np != NULL){
y->np = copyList(x->np);
}else{
y->np = NULL;
}
return y;
}
Run Code Online (Sandbox Code Playgroud)
这不起作用:
Node * copyList(Node *x){
Node y = {x->data,NULL};
if (x->np != NULL){
y.np = copyList(x->np);
}
return &y;
}
Run Code Online (Sandbox Code Playgroud)
我有点困惑为什么.我会假设一个指针本质上是指一个内存地址,返回&y就好了......