Azzera filtri
Azzera filtri

How to solve complex equations?

11 visualizzazioni (ultimi 30 giorni)
Navaneeth
Navaneeth il 13 Feb 2024
Commentato: Navaneeth il 14 Feb 2024
I am trying to solve the following equation.
I have the following script to solve for theta, but getting erro when I am running the program.
Any suggestions is much appreciated.
Thank you.
clc;
clear;
close all;
syms theta
assume(0 <= theta <= 2*pi)
t = 0.4e-3;
n = 1.523;
delta_y = 3;
S1 = solve(delta_y == t*sind(theta)*(1 - sqrt((1-sind(theta)^2)/n^2 - sind(theta)^2)),theta);
  3 Commenti
Torsten
Torsten il 13 Feb 2024
You forgot a bracket around the denominator under the square root.
Navaneeth
Navaneeth il 14 Feb 2024
Sorry that I left out some details. N here is refractive index of the material and t is the thickness of the slab...I want to find the theta in angles for a fixed shift of delta_y.
Thank you.

Accedi per commentare.

Risposta accettata

Torsten
Torsten il 13 Feb 2024
Modificato: Torsten il 13 Feb 2024
Your equation has only complex solutions.
Note that you used sind instead of sin in the function definition. Thus assuming theta in radians is wrong.
clc;
clear;
close all;
syms theta
%assume(0 <= theta <= 2*pi)
t = 0.4e-3;
n = 1.523;
delta_y = 3;
S1 = solve(delta_y == t*sind(theta)*(1 - sqrt((1-sind(theta)^2)/(n^2 - sind(theta)^2))),theta,'ReturnConditions',1,'MaxDegree',3)
S1 = struct with fields:
theta: [2×1 sym] parameters: k conditions: [2×1 sym]
vpa(S1.theta)
ans = 
S1.parameters
ans = 
k
S1.conditions
ans = 
  5 Commenti
Torsten
Torsten il 14 Feb 2024
Modificato: Torsten il 14 Feb 2024
If you use the new parameters, you get back some real solutions:
clc;
clear;
close all;
syms theta
t = 0.7e-3;
n = 1.533;
delta_y = 21.2991*1e-6;
S1 = vpa(solve(delta_y == t*sind(theta)*(1 - sqrt((1-sind(theta)^2)/(n^2 - sind(theta)^2))),theta,'MaxDegree',3))
S1 = 
format long
S1 = double(S1(abs(imag(S1))<1e-6))
S1 =
1.0e+02 * 1.749999973612585 - 0.000000000000000i 0.050000026387415 + 0.000000000000000i
Navaneeth
Navaneeth il 14 Feb 2024
Thank you, this is exactly what I wanted.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by