how can i fix this error?

1 次查看(过去 30 天)
clc
clear
x (1)= 0;
y (1)= 3;
h = 0.05;
for i = 1:10
y (i+1)= y(i)+(6*x^2-3*x^2*y);
x (i+1)= x(i)+h;
end
plot(x,y,'-')
xlabel('x')
ylabel('y')
Error using ^ (line 52)
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'.
Error in odev1 (line 7)
y (i+1)= y(i)+(6*x^2-3*x^2*y);

采纳的回答

Burhan Burak AKMAN
Burhan Burak AKMAN 2021-12-29
You need to change x to x(i) and y to y(i) like this code.
clc
clear
x (1)= 0;
y (1)= 3;
h = 0.05;
for i = 1:10
y (i+1)= y(i)+(6*x(i)^2-3*x(i)^2*y(i));
x (i+1)= x(i)+h;
end
plot(x,y,'-')
xlabel('x')
ylabel('y')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Types 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by