Apostolos Lazidis
Apostolos Lazidis

Reputation: 145

How to appear a a plot in R with step

Hello I try to appear a plot in R with step 0.1 inside the space [0-89] and I do not know how. The code is :

c1 = 1500
c2 = 1600
c3 = 1850
p1 = 1000
p2 = 1300
p3 = 1500
h = 100
f = 500
w = 2 *pi * f
k2 = w / c2

i = complex( real = 0, imaginary = 1 )
 
th1 = ( 0:89 )
th1 = th1 * pi / 180

th2 = asin( pmin(pmax((c2 / c1) * sin (th1),-1.0),1.0) )

th3 = asin(pmin(pmax(( c3 / c2) * sin (th2),-1.0),1.0) )

R12 = (p2 * c2 * cos(th1) - p1 * c1 * cos(th2) ) / (p2 * c2 * cos(th1) + p1 * c1 * cos (th2))

R23 = (p3 * c3 * cos(th2) - p2 * c2 * cos(th3)) / (p3 * c3 * cos(th2) + p2 * c2 * cos (th3))

phi2 = k2 * h * cos(th2)

R13 = (R12 + R23 * exp(2 * i * phi2 ))/ ( 1+ R12 * R23 * exp(2 * i* phi2))
y=abs(R13)

th1=th1*180/pi

plot(th1 , y, type = "l", xlab="Angle of Incidence (Deg)", ylab="|R13|")

axis(side=1, at=seq(0, 100, by=10))
axis(side=2, at=seq(0, 1, by=0.1))

The plot that I take is :

enter image description here

I did it in matlab and the command is t = 0:0.1:89. So if I use this step 0.1 I have a plot like this:

enter image description here

Can you help me on how can I make this work and in R ?

Upvotes: 0

Views: 44

Answers (1)

P. Paccioretti
P. Paccioretti

Reputation: 414

In your code th1 = ( 0:89 ) generates a sequence with a step of 1. If you change that line with th1 = seq(0,89, 0.05), the step will now be 0.05 instead of 1.

Upvotes: 1

Related Questions