Why the function like (1 - cosd(x)) / cosd(x) doesn't create an vector and can't plot?

2 visualizzazioni (ultimi 30 giorni)
I want to plot an function for relative deviation but I got the problem to create the vector. I cant plotting anything.
I try to have on the x-axis the angle in GRAD and on the y-axis the relativ deviation in %.
Do you know where there problem is? I got the following code:
x=-25:0.1:25;
%Grad in Bogenmaß
R = deg2rad(x);
%sin und cos in degree sind sind() und cosd()
F_rel_a = (R - sind(x))/sind(x);
F_rel_c = (1 - cosd(x))/cosd(x);
%%% y = F_rel_a * 100; %not in use
%plotting
figure
plot(x, F_rel_a)
hold on
plot(F_rel_c)
hold off
%%% axis([-25 25 0 2]) %not in use
xlabel('Pendelwinkel in Grad [°]');
ylabel('Relative Abweichung in [%]');
legend({'$sin(\varphi) \approx \varphi$', '$cos(\varphi) \approx 1$'},'Interpreter','latex')

Risposta accettata

Bruno Luong
Bruno Luong il 1 Mar 2023
Modificato: Bruno Luong il 1 Mar 2023
Change / to ./, the "/" is matrix left-division and does something you won't expect for vectors
x=-25:0.1:25;
%Grad in Bogenmaß
R = deg2rad(x);
%sin und cos in degree sind sind() und cosd()
F_rel_a = (R - sind(x))./sind(x);
F_rel_c = (1 - cosd(x))./cosd(x);
%%% y = F_rel_a / 100; %not in use
%plotting
figure
plot(x, F_rel_a)
hold on
plot(F_rel_c)
hold off
%%% axis([-25 25 0 2]) %not in use
xlabel('Pendelwinkel in Grad [°]');
ylabel('Relative Abweichung in [%]');
legend({'$sin(\varphi) \approx \varphi$', '$cos(\varphi) \approx 1$'},'Interpreter','latex')
  1 Commento
Janis Anger
Janis Anger il 1 Mar 2023
Ah perfectly, it works! Thank you! I also see I forgot the x in one of the plots:
hold on
plot(x, F_rel_c) %<----- insert x
hold off

Accedi per commentare.

Più risposte (1)

Torsten
Torsten il 1 Mar 2023
%sin und cos in degree sind sind() und cosd()
F_rel_a = (R - sind(x))./sind(x)
F_rel_c = (1 - cosd(x))./cosd(x)
instead of
%sin und cos in degree sind sind() und cosd()
F_rel_a = (R - sind(x))/sind(x)
F_rel_c = (1 - cosd(x))/cosd(x)

Categorie

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

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by