solving trigonometric equation on matlab

hello
im trying to solve tan(x)+0.0042*x=0 on matlab. This equation gives infinite solutions and i want them .So any Help?
f=@(x) tan(x)+(x*(4.21*10^-3));
x=0:0.01:100;
plot(x,f(x))
cnt=1;
for ii=1:100
rt(cnt)= fzero(f,ii);
cnt=cnt+1;
end

2 Comments

You got several answers to your question. SO there is NO reason to repost the identical question on what is surely a homework assignment.
For what it's worth, I'm pretty sure that double-post occurred at the same time, long before I answered. I figured it was an accidental dupe.
I'm also assuming there were just the two posts!

Sign in to comment.

Answers (2)

DGM
DGM on 27 Mar 2021
Edited: DGM on 27 Mar 2021
There are probably symbolic ways to approach this, but let's just say you want numeric solutions like what you're doing here. Also, let's assume you don't actually want an infinite number of numeric solutions.
It's helpful to understand approximately where the solutions are going to occur and their period. Given the equation
we know we'll have a intersection at x=0. Since the value of the LHS of the equation grows slowly compared to the values achieved by the RHS within its period, we can probably assume that our roots will lie close to where they would if the LHS were zero (i.e. they'll have an approximate period of pi). Making this assumption also ensures that our initial estimate always starts out away from the discontinuities.
So you might try setting up your estimates and using fzero() like this:
f=@(x) tan(x)+(x*(4.21*10^-3));
x=0:0.01:100*pi;
plot(x,f(x)); hold on
rt0=0:pi:100*pi; % this is our estimate of where roots should be
rt=zeros([1 numel(rt0)]);
for ii=1:numel(rt0)
% search for a zero crossing in the region bounded by,
% but not including the local discontinuities.
rt(ii)= fzero(f,[-pi/2 pi/2]*(1-1E-6) + rt0(ii));
end
% plot the function, root estimates, and roots.
plot(rt0,zeros(size(rt)),'bo')
plot(rt,zeros(size(rt)),'ro')
ylim([-1 1]*10)
Importantly, note that the x0 argument given to fzero() is not given as a point, but as an interval surrounding rt0(ii). This is to ensure that fzero() does not consider the apparent roots that occur as a consequence of the local discontinuities.
Zooming in on the plot near x=100*pi, we can see the relationship between the function and our calculated and estimated roots (right-click, View Image)
But dear if i write your code , i don't get the roots , So , how can i get them?

1 Comment

The calculated roots are in the vector rt
>> rt'
ans =
1.0e+02 *
0
0.031284227552660
0.062568500583530
0.093852864476928
0.125137364429868
0.156422045359617
0.187706951812672
0.218992127875639
0.250277617088421
0.281563462360164
0.312849705888319
0.344136389081213
0.375423552484436
0.406711235711354
0.437999477378004
0.469288315042600
0.500577785149825
0.531867922980075
0.563158762603738
0.594450336840607
0.625742677224436
0.657035813972650
0.688329775961171
0.719624590704283
0.750920284339447
0.782216881616931
0.813514405894100
0.844812879134203
0.876112321909453
0.907412753408180
0.938714191445856
0.970016652479725
1.001320151626815
1.032624702685070
1.063930318157337
1.095237009277979
1.126544786041821
1.157853657235205
1.189163630468890
1.220474712212556
1.251786907830679
1.283100221619550
1.314414656845214
1.345730215782131
1.377046899752359
1.408364709165072
1.439683643556246
1.471003701628348
1.502324881289885
1.533647179694669
1.564970593280685
1.596295117808439
1.627620748398694
1.658947479569498
1.690275305272427
1.721604218927981
1.752934213460058
1.784265281329473
1.815597414566471
1.846930604802202
1.878264843299130
1.909600120980369
1.940936428457912
1.972273756059768
2.003612093855989
2.034951431683599
2.066291759170432
2.097633065757888
2.128975340722616
2.160318573197159
2.191662752189563
2.223007866601980
2.254353905248294
2.285700856870787
2.317048710155881
2.348397453748977
2.379747076268428
2.411097566318664
2.442448912502516
2.473801103432755
2.505154127742880
2.536507974097194
2.567862631200180
2.599218087805228
2.630574332722730
2.661931354827565
2.693289143066027
2.724647686462190
2.756006974123771
2.787366995247487
2.818727739123955
2.850089195142140
2.881451352793398
2.912814201675106
2.944177731493929
2.975541932068738
3.006906793333180
3.038272305337953
3.069638458252774
3.101005242368080
3.132372648096460
Mind you, that's just the first 101 non-negative roots. It's not a general symbolic solution for all roots.

Sign in to comment.

Asked:

on 27 Mar 2021

Commented:

DGM
on 27 Mar 2021

Community Treasure Hunt

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

Start Hunting!