- Convert your equation into a MATLAB function that returns zero when the equation is satisfied.
- Use "fsolve" to find the root, starting with a default or randomized initial guess to ensure convergence.
Find the m of nonlinear equation without initial input m. Please help me, my supervisor ask me to find m without input initial m from right. I know this is nonlinear equation.
2 views (last 30 days)
Show older comments
% Given data
sigma = [ 137.478; 162.072; 162.239; 162.818; 164.010; 164.401; 165.872; 167.721; 169.748; 171.390; 177.637; 180.296; 180.572; 181.049; 182.188; 182.862; 187.895; 187.924; 188.066; 188.208; 188.251; 189.464; 190.053; 190.818; 190.987; 191.169; 191.622; 213.997; 218.369; 221.124 ];
% number of specimen
n = numel( sigma )
0 Comments
Accepted Answer
Shubham
on 4 Sep 2024
Hi Trong,
To solve the nonlinear equation for "m" without an initial guess, you can use MATLAB's "fsolve" or "fzero" functions.
Here's how you can solve it using "fsolve" function:
Below is the MATLAB script to illustrate these steps:
% Given data
sigma = [137.478; 162.072; 162.239; 162.818; 164.010; 164.401; 165.872; ...
167.721; 169.748; 171.390; 177.637; 180.296; 180.572; 181.049; ...
182.188; 182.862; 187.895; 187.924; 188.066; 188.208; 188.251; ...
189.464; 190.053; 190.818; 190.987; 191.169; 191.622; 213.997; ...
218.369; 221.124];
n = numel(sigma);
% Define the function to solve
fun = @(m) (sum(log(sigma) .* (sigma.^m)) / sum(sigma.^m)) - (1/m) - (sum(log(sigma)) / n);
% Solve using fsolve
options = optimset('Display', 'off'); % Suppress output
m_initial_guess = 1; % You can vary this guess or use different techniques
m_solution = fsolve(fun, m_initial_guess, options);
fprintf('The solution for m is: %.4f\n', m_solution);
Refer to the following MathWorks documentation link for more information on "fsolve":
Hope this helps.
3 Comments
More Answers (1)
John D'Errico
on 4 Sep 2024
Edited: John D'Errico
on 4 Sep 2024
Not homework, but barely any effort made. Sigh. This is apparently your job. You need to start learning MATLAB.
sigma = [ 137.478; 162.072; 162.239; 162.818; 164.010; 164.401; 165.872; 167.721; 169.748; 171.390; 177.637; 180.296; 180.572; 181.049; 182.188; 182.862; 187.895; 187.924; 188.066; 188.208; 188.251; 189.464; 190.053; 190.818; 190.987; 191.169; 191.622; 213.997; 218.369; 221.124 ];
First, create a function that evaluates this expresssion, as a function of m, and incidentally sigma. I'll precompute the log of the sigma vector, since it will be used often.
Note that the last term is simply the mean of the vector log(sigma). I could probably precompute that too.
logsigma = log(sigma);
fun = @(m) -1/m + sum(logsigma.*sigma.^m)/sum(sigma.^m) - mean(logsigma);
Note that fun is just one equation, as a function of one variable. It returns a scalar value. Before you do ANYTHING, verify that it returns something that makes sense.
fun(1)
fun(3)
Now, PLOT THE FUNCTION! ALWAYS PLOT EVERYTHING. Make sure you understand what is happening.
fplot(fun,[0,5])
grid on
xlabel m
Hmm. It looks like it MAY cross zero, for some larger value of m. Best if I redo the plot, changing the axes a bit to target the region I care about.
By the eay, the warning about vectorization is just a warning. fplot wants to be able to pass in multiple values for m all at once, and this objective is not vectorized. In this case, for a simple plot, I don't really care.
fplot(fun,[1,20])
grid on
xlabel m
ylim([-1,1])
Do you see what I am doing? Before I throw something nilly willy into a solver, I want to see what is happening, to visualize if a solution even exists.
Finally, what solver do I use? FZERO! fzero is designed to solve nonlinear rootfinding problems with one unknown variable, and one equation. It is designed to be both efficient and robust against difficult problems. It is especially good if you can bound the solution between two limits, known as a bracket, although it would still often work quite well if I gave it only one starting point.
[xsol,fval,exitflag] = fzero(fun,[1,20])
So fzero is happy. exitflag=1 is good. The objective is zero, to within tolerances.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!