我有一个公式
F = (-k.^(3/2) .* sqrt(4 .* c .* x + k) + 2 .* x .* k .* c + k.^2) / (2 .* c)
Run Code Online (Sandbox Code Playgroud)
并且我试图将f映射到c的一系列值,对于常数x和k值,如下所示:
x = 0.01;
c = 10000:10000:100000;
k = 100000;
F = (-k.^(3/2) .* sqrt(4 .* c .* x + k) + 2 .* x .* k .* c + k.^2) / (2 .* c)
Run Code Online (Sandbox Code Playgroud)
在这一点上,我假设matlab会给我一个与c相同大小的向量,但它只是打印:
F =
47.1563
Run Code Online (Sandbox Code Playgroud)
针对常数c和x的k值范围绘制F可以正常工作,但上述情况并非如此.
有人可以帮我解释一下吗?
我已经完成了编写一些代码的任务,该代码从图中获取节点列表,并确定它们是否处于正确的拓扑顺序.
该图在内存中表示如下:
typedef struct graph_t* Graph;
typedef struct node_t* Node;
struct node_t {
int id;
/*incoming edges*/
Linked_list incoming;
/*outgoing edges*/
Linked_list outgoing;
};
struct graph_t {
int order;
int size;
Node nodes;
};
Run Code Online (Sandbox Code Playgroud)
为简洁起见,我省略了链表的实现,但它只是链表的标准实现.
我也得到了以下算法(伪代码):
L <- topologically sorted list of nodes
V <- empty list of visited nodes
for each node n in L do
add n to V
for each node m reachable from n do
if m in V then L is not sorted
Run Code Online (Sandbox Code Playgroud)
我确实理解拓扑顺序的定义,但我不明白这将如何或为什么会验证拓扑排序.
这个算法怎么样?此外,鉴于图表的上述表示,该如何 …
我正在尝试将div元素的高度设置为屏幕高度减去固定数量的像素.
我正在构建一个带有角度的单页应用程序,现在它正处于初期阶段.该页面目前包含一个标题栏,它是一个固定的24px高度.
直接位于此标题下方的是<app-root></app-root>由angular自动生成的组件,其中包含单个div <div id="work-area"><div>.
我想要做的是让这个#work-areadiv从标题的底部延伸到屏幕的底部,就像screen.height - 24px这是在纯javascript中完成的.
我不知道该如何解决这个问题.到目前为止,我尝试了一些方法:
ngStyle属性指令,但这只需要纯CSS而不是javascript,所以我遇到了与上面相同的问题.以下是我的文件,因为它使问题更清楚:
//app-root component
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: '<div id="work-area"></div>',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
}
Run Code Online (Sandbox Code Playgroud)
的index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>WorkspacePrototype</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<div class="overflowing-bar">
<div id="header">
</div>
</div>
<app-root>Loading...</app-root>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
全球styles.css …
我在尝试迭代python中的嵌套列表时遇到问题,并将列表中的值复制到另一个嵌套列表中,在我去的时候为每个值添加一个.
说我有一个清单
input = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Run Code Online (Sandbox Code Playgroud)
我尝试创建第二个列表(称之为output),是:
output = [[x + 1 for int(x)in y] for y in input]
Run Code Online (Sandbox Code Playgroud)
这给了我错误
SyntaxError: can't assign to function call
Run Code Online (Sandbox Code Playgroud)
编辑:
感谢答案,问题是尝试调用int(x) - 这完全没必要.此外,我对调用列表似乎没有任何问题input
我有一个非常奇怪的问题,试图在分配的内存上调用free导致我的程序崩溃.
这是相关的代码:
int i, count;
char *specifier;
char aisle[1];
count = 0;
/*Find name of the new item and assign to the name field of new_node...*/
for (i = 0; input[i] != ','; i++){
count++;
}
specifier = (char*)malloc((count+1)*sizeof(char));
if (specifier == NULL){
printf("Out of memory. Shutting down.\n");
exit(EXIT_FAILURE);
}
for (i = 0; input[i] != ','; i++){
specifier[i] = input[i];
}
specifier[count+1] = '\0';
new_node->name = specifier;
printf("%s\n", new_node->name);
free(specifier); /*PROGRAM CRASHES HERE*/
printf("boom\n");
specifier = NULL;
/*Function continues …Run Code Online (Sandbox Code Playgroud)