multiply by two matrix

1 vue (au cours des 30 derniers jours)
shiv gaur
shiv gaur le 26 Sep 2021
Mj = [cos (kj hj) i*sin(kj hj) /kj ; i*kj*sin(kj hj) cos (kj hj) ];
kj=sqrt(nj^2*k02-x^2);
Take
n1=1.521;n2=2.66;k0=1;h1=1.5e-6;h2=1e-6
multiply M1*M2
  4 commentaires
shiv gaur
shiv gaur le 26 Sep 2021
Modifié(e) : Walter Roberson le 27 Sep 2021
%this is program
function kp1
close all;
clear all;
function y=F(x)
for t2=1
k0=1;
n1=1.521;
%n2=2.66;
n2=4.1-0.211*1i;
ns=1.512;
%nc=0.15-1i*3.2;
nc=1;
k1=sqrt(n1.^2*k0.^2-x.^2);
k2=sqrt(n2.^2*k0.^2-x.^2);
t1=1.5;
m11= cos(t1*k1)*cos(t2*k2)-(k2/k1)*sin(t1*k1)*sin(t2*k2);
m12=(1/k2)*(cos(t1*k1)*sin(t2*k2)*1i) +(1/k1)*(cos(t2*k2)*sin(t1*k1)*1i);
m21= (k1)*cos(t2*k2)*sin(t1*k1)*1i +(k2)*cos(t1*k1)*sin(t2*k2)*1i;
m22=cos(t1*k1)*cos(t2*k2)-(k1/k2)*sin(t1*k1)*sin(t2*k2);
A=[m11 m12 ; m21 m22];
disp(eig(A))
gs=x.^2-ns.^2*k0.^2;
gc= x.^2-nc.^2*k0.^2;
y= 1i*(gs*m11+gc*m22)-m21+gc*gs*m12 ;
%y=x^2+x+1;
end
end
p0=1;
p1=1.5;
p2=2;
tol = 10^-5;
n = 50;
h1 = p1 - p0;
h2 = p2 - p1;
del1 = (F(p1)-F(p0))./h1;
del2 = (F(p2)-F(p1))./h2;
d = (del2-del1)./(h2+h1);
I = 3;
%Step 2
while I <= n
%Step 3
b = del2+h2.*d;
D = sqrt(b.^2-4.*F(p2).*d); % could be complex
%Step 4
if abs(b - D) < abs(b + D)
E = b + D;
else
E = b - D;
end
%Step 5
h = -2.*F(p2)./E;
p = p2 + h;
if I == 3
table{1} = 'Muller''s Method Iterations';
table{2}=' I P f(P) ';
table{3}='-----------------------------------------------------';
end
str = sprintf('%3u: % 6.6f + %6.6fi % 6.6f + %6.6fi',I,real(p),imag(p),real(F(p)),imag(F(p)));
table{I + 1} = str; %#ok<*AGROW>
%Step 6
if abs(h) < tol
val = p;
table = char(table);
break
end
p0 = p1;
p1 = p2;
p2 = p;
h1 = p1 - p0;
h2 = p2 - p1;
del1 = (F(p1)-F(p0))./h1;
del2 = (F(p2)-F(p1))./h2;
d = (del2-del1)./(h2+h1);
I = I + 1;
end
disp(p)
end
Jan
Jan le 26 Sep 2021
Please format your code properly. Use the icons on top of the field for editing in the forum.
You still did not ask a question.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 27 Sep 2021
syms x
n = [1.521, 2.66];
k0 = 1;
h = [1.5e-6, 1e-6];
k = @(j) sqrt(n(j).^2*k0.^2-x.^2);
M = @(j) [
cos(k(j) .* h(j)), i*sin(k(j) .* h(j))/k(j)
i .* k(j) .* sin(k(j).*h(j)), cos(k(j) .* h(j))
]
M = function_handle with value:
@(j)[cos(k(j).*h(j)),i*sin(k(j).*h(j))/k(j);i.*k(j).*sin(k(j).*h(j)),cos(k(j).*h(j))]
M12 = M(1) * M(2)
M12 = 

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by