Why am I getting the error "Array indices must be positive integers or logical values."?

1 view (last 30 days)
clear all;clc;
x=1;y=2
a=0.25
k=2;n=5;
u=real(complex(k,n)+sqrt(complex(k,n).^2-4.*a.^2))
v=imag(complex(k,n)+sqrt(complex(k,n).^2-4.*a.^2))
kfinal=(x.*(u.*x-v.*y)-y(u.*y+v.*x))./(x.^2+y.^2)+a.^2.*(x.*(u.*x-v.*y)+y(u.*y+v.*x))./((u.*x-v.*y).^2+(u.*y+v.*x).^2);
nfinal=(x.*(u.*y+v.*x)+y(u.*x-v.*y))./(x.^2+y.^2)+a.^2.*(x.*(u.*x+v.*y)-y(u.*x+v.*y))./((u.*x-v.*y).^2+(u.*y+v.*x).^2);
Error :
Array indices must be positive integers or logical values.
Error in deneme (line 9)
kfinal=(x.*(u.*x-v.*y)-y(u.*y+v.*x))./(x.^2+y.^2)+a.^2.*(x.*(u.*x-v.*y)+y(u.*y+v.*x))./((u.*x-v.*y).^2+(u.*y+v.*x).^2);

Accepted Answer

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 25 May 2021
Hi,
You have overlooked .* after y:
kfinal=(x.*(u.*x-v.*y)-y.*(u.*y+v.*x))./(x.^2+y.^2)+a.^2.*(x.*(u.*x-v.*y)+y.*(u.*y+v.*x))./((u.*x-v.*y).^2+(u.*y+v.*x).^2);
nfinal=(x.*(u.*y+v.*x)+y.*(u.*x-v.*y))./(x.^2+y.^2)+a.^2.*(x.*(u.*x+v.*y)-y.*(u.*x+v.*y))./((u.*x-v.*y).^2+(u.*y+v.*x).^2);

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!