フィルターのクリア

???In an assignment A(I) = B, the number of elements in B and I must be the same.???

1 回表示 (過去 30 日間)
Jose
Jose 2014 年 8 月 20 日
コメント済み: Jose 2014 年 8 月 20 日
Hi I am getting this error ???In an assignment A(I) = B, the number of elements in B and I must be the same.??? ???Error in lab6 (line 17) t(i+1) = t +(i.*h)???
So basically I want to calculate the values in a for loop and put them in a zeros matrix. I am trying to program a Euler's Method.
%%Tasks
clc, clear all
func = @(t,x) -t.*x;
% func = @(t,x) sinh(x ./ (t+1));
% func = @(t,x) (t*x.^2)*cos(x.^2);
t0 = 0; %Initial Value
t1 = 5; %Final Value
x = 1; %Initial Value
h = 0.1; %Step size
steps = (t1 - t0) / h %Steps need to be taken
xarrays = zeros(1,steps);
tarrays = zeros(1,steps);
t = t0
for i = 1:steps
t(i+1) = t +(i.*h)
x(i+1) = x(i) + h.*func(t(i),x(i));
xarrays = x(i+1)
tarrays = t(i+1)
end
xarrays(:,t1)

採用された回答

Image Analyst
Image Analyst 2014 年 8 月 20 日
t is an array. A 2D array of many elements. You cannot assign a whole array to just one element of it, t(i).
For example, let's say t was a 4 by 4 array and i was 3. Then you're trying to assign a 4 by 4 array (16 elements) to just a single element, t(3). You can't do that.
Try to think some more about the logic of this lab6 homework problem.
  1 件のコメント
Jose
Jose 2014 年 8 月 20 日
Thank you. I still have to think of the solution but thanks :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePulsed Waveforms についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by