找出这个问题一直很麻烦。这是我的第一个Scilab作业,所以我还是个新手。
表1将°F转换为K.
我附上了截至目前为止我所获得的截图(这是我在网上发现的一种模式),但我被卡住了。我对输入和linspace(第1和第2部分)有正确的想法吗?
非常感谢任何和所有的帮助!
我不确定如何使用公式(200 / Increment1)+1,但这就是我理解这个问题的方法,它给出了所需的输出
clear
clc
Increment1=input("Enter number of elements:")
F=linspace(0,200,200/Increment1+1)
for n=1:(200/Increment1)+1
k=(5/9)*(F(n)+459.67)
K(n)=k
end
disp(" F K")
F=F'
A=cat(2,F,K)
disp(A)
输出 -
Enter number of elements:100
F K
0. 255.37222
100. 310.92778
200. 366.48333
在scilab中有两种方法来定义一个向量:使用x=start:step:end
中的步骤或x=linspace(start,end,number)
中的元素总数
因此,如果你希望Increment1
元素按照建议,你将不得不写F=linspace(0,200,Increment1)
。
事实上,F的两个元素之间的步骤是(end-start)/(number-1)
所以你也可以写F=0:200/(Increment1-1):200
。你的原始问题可能有误,因为我不能在数学上理解'200 / Increment1 + 1'部分
正如@ user5694329所说,你不应该考虑使用for
循环,而是使用像K=(5/9)*(F+459.67)
这样的线性代数更多转换为:取向量F,为每个元素添加459.67,并将其乘以5/9
还要注意x=x'
(由Rohan建议)计算矩阵/向量的转置共轭。对于真正的价值观而言,无关紧要,但如果您使用复杂数字,将来可能会遇到一些麻烦。使用x=x.'
代替或x=transpose(x)'
。最后,如果你需要一个特定的形状,最好使用矩阵函数:x = matrix(x,-1,1)
转换为'take x,并将其设为1列,并根据需要添加多行'(显然x = matrix(x,1,-1)
是行版本)。阅读帮助以获取更多详细信息help matrix
。
完整的答案是(这对我来说很有意义)
clear;
clc;
// 1.Request the user to input the number of elements you want in a vector.
// Call this variable “Increment1”.
Increment1=input("Enter number of elements:");
// Use the linspace function to create a vector from 0°F to 200°F. Name this variable “F”.
F=linspace(0,200,Increment1) // or F=0:200/(Increment1-1):200;
// NOT UNDERSTOOD : and uses the number of elements input by the user in the following formula (200/”increment1”)+1.
F=matrix(F,1,-1); // BONUS : we assure that F is a row
// Use the formula (5/9)*(F +459.67) to create a vector of K values. Name this variable “K”.
K=(5/9)*(F+459.67); // K is also a row since F is
// 4. Concatenate F and K into a 2 row matrix (such that F values are directly on top of K values). Name this variable “A”
A = [F;K] // or cat(1,F,K) : Takes F, change row (;), add K
// Display A
disp(A)