简体   繁体   English

请帮助:在分配A(I)= B中,B和I中的元素数必须相同。 的MATLAB

[英]Please Help: In an assignment A(I) = B, the number of elements in B and I must be the same. MATLAB

I was asked in an assignment to use Euler's method to determine the values of t and y from t=0:1000. 要求我在一次作业中使用欧拉方法从t = 0:1000确定t和y的值。 I have all the basic code and parameters down but when i put my Euler's equation in I get the error code 我记下了所有基本代码和参数,但是当我将欧拉方程放进去时,我得到了错误代码

In an assignment A(I) = B, the number of elements in B and I must be the same. 在分配A(I)= B中,B和I中的元素数必须相同。

Error in Project1 (line 24) Ay(i+1) = Ay(i) + (dAy)*x; Project1(第24行)中的错误Ay(i + 1)= Ay(i)+(dAy)* x;

How could I change these variables between vectors and scalars to allow the equation to run? 如何在矢量和标量之间更改这些变量以允许方程运行? My full code can be found below: 我的完整代码可以在下面找到:

dt=x;
Ay=zeros(1,1001);
Ay0=1250;
Ay(1) = Ay0;
t=0;
y=0;
t=0:dt:1000;
for i=1:1000
    if y > 10
        Qout=3*(y-10).^1.5;
    else
        Qout=0;
    end
    Qin=1350*sin(t).^2;
    dAy=Qin-Qout;
    Ay(i+1) = Ay(i) + dAy*dt;
end
plot(t,y);

The problem lies in the line of your code: 问题出在代码行中:

Ay(i+1) = Ay(i) + dAy*dt;

dAy*dt returns a vector. dAy * dt返回一个向量。

When you add it to Ay(i) you still end up with a vector. 当您将其添加到Ay(i)时,仍然会得到一个向量。

Ay(i+1) is a SINGLE element within a vector. Ay(i + 1)是向量中的单个元素。

You Cannot assign a vector quantity to an element within a vector. 您不能将向量数量分配给向量中的元素。

The issue is that your variable "Qin" is not a number it is a vector containing sin values of the whole vector t. 问题是您的变量“ Qin”不是数字,它是一个包含整个向量t的sin值的向量。 Similarly your "dAy" is also a vector. 同样,您的“ dAy”也是一个向量。 Hence it cannot be stored in a variable Ay. 因此,它不能存储在变量Ay中。
if your dt =x = 1, just replace sin(t) with sin(i) ie replace 如果您的dt = x = 1,只需将sin(t)替换为sin(i),即替换

Qin=1350*sin(t).^2; Qin = 1350 * sin(t)。^ 2; by Qin=1350*sin(i).^2; 由Qin = 1350 * sin(i)。^ 2;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何摆脱这个MATLAB错误? “在赋值A(I)= B中,B和I中的元素数必须相同。” - How do I get rid of this MATLAB error? “In an assignment A(I) = B, the number of elements in B and I must be the same.” 不知道如何纠正:“在赋值A(I)= B中,B和I中的元素数必须相同。” - Don't know how to Correct : “In an assignment A(I) = B, the number of elements in B and I must be the same.” 马赛克:??? 在赋值 A(I) = B 中,B 和 I 中的元素个数必须相同 - MATLAB: ??? In an assignment A(I) = B, the number of elements in B and I must be the same 在分配A(I)= B中,B和I中的元素数必须相同 - In assignment A(I) = B, the number of elements in B and I must be the same 在分配A(I)= B中,B和I中的元素数必须相同 - In an assignment A(I) = B, the number of elements in B and I must be the same 赋值A(I)= B时出错,B和I中的元素数必须相同 - error with an assignment A(I) = B, the number of elements in B and I must be the same 在赋值A(I)= B中,B和I中的元素数必须相同 - In an assignment A(I) = B, the number of elements in B and I must be the same MATLAB:错误:在A(I)= B中,B和I中的元素数必须相同 - MATLAB: error: In A(I) = B, the number of elements in B and I must be the same 在赋值 A(:) = B 中,A 和 B 中的元素数量必须相同 - In an assignment A(:) = B, the number of elements in A and B must be the same 在赋值 A(:) = B 中,A 和 B 中的元素数量必须相同 - In an assignment A(:) = B, the number of elements in A and B must be the same
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM