Why am I getting an answer "1×0 empty double row vector"?
Show older comments
In thi s script I was asked to solve a quadaric equation that would give me complex numers. With the complex numbers in an array i need to find when the roots of the real and imaginary parts are of equal magnitude. Then plot these roots using green triangles. The solution should consist of 2 complex conjugate pairs (you may ignore solutions at the origin).
I was told to use the find() command but seem to be struggling with it and getting answers to plot.
Here is my code.
clear;
close all
clc
alpha1 = 3; alpha2 = 1.2; alpha3 = 4;
beta = -1:1e-3:2;
a = (1./beta);
b = (alpha1.*beta.^3) - alpha2;
c = alpha3.*beta;
s1 = (-b + sqrt(b.^2-(4.*a.*c)))./(2.*a);
s2 = (-b - sqrt(b.^2-(4.*a.*c)))./(2.*a);
s1real = real(s1);
s1imag = imag(s1);
s2real = real(s2);
s2imag = imag(s2);
plot(s1real, s1imag, 'b')
hold
plot(s2real, s2imag, 'b')
grid on
axis([-4 2 -2 2]);
xlabel('Real(s)')
ylabel('Imag(s)')
line([0 0], ylim); % draw x-axis
line(xlim, [0 0]); % draw y-axis
[s1Imag_max,beta_max1]=max(s1imag);
beta_maxImag1 = beta(beta_max1)
[s2Imag_max,beta_max2]=max(s2imag);
beta_maxImag2 = beta(beta_max2);
s1real_red = s1real(beta_max1);
s1imag_red = s1imag(beta_max1);
plot(s1real_red,s1imag_red,'ro')
s2real_red = s2real(beta_max2);
s2imag_red = s2imag(beta_max2);
plot(s2real_red,s2imag_red,'ro')
s1real_abs = abs(s1real);
[s1Im_zeroReal, beta_zero1] = min(s1real_abs);
beta_zeroReal = beta(beta_zero1)
s2real_abs = abs(s2real);
[s2Im_zeroReal, beta_zero2] = min(s2real_abs);
beta_zeroReal2 = beta(beta_zero2);
s1real_black = s1real(beta_zero1);
s1imag_black = s1imag(beta_zero1);
plot(s1real_black,s1imag_black,'ks')
s2real_black = s2real(beta_zero2);
s2imag_black = s2imag(beta_zero2);
plot(s2real_black,s2imag_black,'ks')
s1imag_abs = abs(s1imag);
s2imag_abs = abs(s2imag);
s1_non = find(s1real_abs==s1imag_abs)
s2_non = find(s2real_abs==s2imag_abs)
plot(0,0,'g^')
Answers (1)
David Hill
on 16 Feb 2022
Really too many points to do an effective scatter plot. Recommend reducing the size of beta.
alpha1 = 3; alpha2 = 1.2; alpha3 = 4;
beta = -1:1e-3:2;
beta =beta(beta~=0);%removes infinity for an 'a' value
a = (1./beta);
b = (alpha1.*beta.^3) - alpha2;
c = alpha3.*beta;
s1 = (-b + sqrt(b.^2-(4.*a.*c)))./(2.*a);
s2 = (-b - sqrt(b.^2-(4.*a.*c)))./(2.*a);
scatter(real(s1),imag(s1));
hold on;
scatter(real(s2),imag(s2));
Categories
Find more on Correlation and Convolution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!