write code to solve trigonometric equation

Hello !
I am a begineer to matlab and i need to solve this trignometric equation using matlab graphically, could anyone help
func : cosh x cos x + 1
I tried to write the following code but it didn't work anymore
p= @(x) (cosh(x)*cos(x)+1);
x=[-2*pi:0.1:2*pi];
plot (x,p(x));
i tried to plot this equation with the given intervial but this message was shown "nonconformant arguments (op1 is 1x126, op2 is 1x126)
error: called from"
thanks

 채택된 답변

VBBV
VBBV 2023년 4월 29일
p= @(x) (cosh(x).*cos(x)+1);
x=[-2*pi:0.1:2*pi];
plot(x,p(x));

댓글 수: 3

Ahmed
Ahmed 2023년 4월 29일
thanks so much !, how to catch the x-roots from the graph ?
p= @(x) (cosh(x).*cos(x)+1);
x=[-2*pi:0.1:2*pi];
px = p(x);
plot(x,px);
mask = find(px(1:end-1) .* px(2:end) <= 0);
[x(mask).', px(mask).', px(mask+1).']
ans = 4×3
-4.7832 5.2263 -0.5786 -1.8832 -0.0336 0.3553 1.8168 0.2310 -0.1779 4.6168 -3.8278 1.2474
Ahmed
Ahmed 2023년 4월 29일
excellent! thanks for your answer!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

릴리스

R2022a

질문:

2023년 4월 29일

댓글:

2023년 4월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by