Made some modifications, hope this helps.. format short syms x % Define the function and its derivative f = @(x) x*log10(x) - 1.2; df = matlabFunction(diff(f(x), x)); % Convert symbolic derivative to function % Initial guess and parameters x0 = 1.5; n = 6; iter = 1; err = abs(f(x0)); epsilon = 5 * 10^(-n - 1); itermax = 70; % Array to store iteration data HG = []; % Check if the derivative at initial guess is non-zero if abs(df(x0)) < 10^(-9) disp('Wrong choice of initial Guess'); else % Newton-Raphson iteration while (iter epsilon) x1 = x0 - f(x0) / df(x0); err = abs(f(x1)); % Update error with new x1 value HG = [HG; iter, x0, f(x0), err]; % Append current iteration data iter = iter + 1; x0 = x1; % Update x0 for next iteration end end % Display results disp('====='); disp('Output Table with Iteration-wise Results'); % Convert results to table with column names Result = array2table(HG, 'VariableNames', {'Iteration', 'x', 'f(x)', 'Error'}); disp(Result); % Round solution to n decimal places x0 = round(x0, n); fprintf('Converged solution after %d iterations ', iter - 1); fprintf('Root is %2.*f ', n, x0);
@@DrHarishGarg I have found a matlab code that finds the roots of two functions of two variables by using Newton Method. I know that for quadratic equation the roots should be two values; one +ve and one -ve of the same root value. This can be noticed with using different initial values. Thats why I raised my question earlier. However, how could we let the matlab code shows the both values without plotting. Hope my question is clear.
@@DrHarishGarg Hey! I'm a Freelancer and I do have pirated versions of the softwares. And I was planning to make videos on mechanical softwares like MATLAB, Solidworks, AutoCAD, etc on TH-cam. Like how to design a particular thing or how to write a code for a particular problem. All these softwares cost 1000s of dollars a year for individual/commercial license which obviously I can't afford. If you could help me out with a few questions, I would be really grateful of you!!! 1) When I apply for monetization, will I be asked whether I have commerical licenses of the aforementioned softwares by TH-cam? 2) If TH-cam doesn't ask for commercial licenses and after that my content is monetized, at what point can I expect these companies to send me a notice regarding the licenses? At 10k subscribers? 50k? 100k? 3) How much money do TH-camrs with 10-50k subscribers from 3rd world countries like India get monthly? Any idea? 4) Is it really worth it? I mean I do have the skills and knowledge but I honestly don't think I would be able to afford these softwares until and unless I start earning 500-1000$ per month via TH-cam.
Made some modifications, hope this helps..
format short
syms x
% Define the function and its derivative
f = @(x) x*log10(x) - 1.2;
df = matlabFunction(diff(f(x), x)); % Convert symbolic derivative to function
% Initial guess and parameters
x0 = 1.5;
n = 6;
iter = 1;
err = abs(f(x0));
epsilon = 5 * 10^(-n - 1);
itermax = 70;
% Array to store iteration data
HG = [];
% Check if the derivative at initial guess is non-zero
if abs(df(x0)) < 10^(-9)
disp('Wrong choice of initial Guess');
else
% Newton-Raphson iteration
while (iter epsilon)
x1 = x0 - f(x0) / df(x0);
err = abs(f(x1)); % Update error with new x1 value
HG = [HG; iter, x0, f(x0), err]; % Append current iteration data
iter = iter + 1;
x0 = x1; % Update x0 for next iteration
end
end
% Display results
disp('=====');
disp('Output Table with Iteration-wise Results');
% Convert results to table with column names
Result = array2table(HG, 'VariableNames', {'Iteration', 'x', 'f(x)', 'Error'});
disp(Result);
% Round solution to n decimal places
x0 = round(x0, n);
fprintf('Converged solution after %d iterations
', iter - 1);
fprintf('Root is %2.*f
', n, x0);
Dear Sir, Your lectures are really very helpful. Please upload the videos on the MATLAB implementation of Descent Methods.
Appreciate much Dr Harish ,,,, God bless u ,, you have been help me so much ,,,, 🙏🙏👍👍
An advice to improve the algorithm. The IF condition should be "abs(dfx(x0))
sir i need the code for an ODE by using newton raphson method. can you give me?
This code is not running in my system.
Same
Thank you dr. .... I have a question; does the value of roots changes if we use different value for the initial point?
No
@@DrHarishGarg I have found a matlab code that finds the roots of two functions of two variables by using Newton Method. I know that for quadratic equation the roots should be two values; one +ve and one -ve of the same root value. This can be noticed with using different initial values. Thats why I raised my question earlier. However, how could we let the matlab code shows the both values without plotting. Hope my question is clear.
That's called as multiple roots of f(x)
How can I write this code in "c"?
Please sir code de dein Ricci tensor ka lea
Thank you Dr.
My pleasure dear
@@DrHarishGarg Hey! I'm a Freelancer and I do have pirated versions of the softwares. And I was planning to make videos on mechanical softwares like MATLAB, Solidworks, AutoCAD, etc on TH-cam. Like how to design a particular thing or how to write a code for a particular problem. All these softwares cost 1000s of dollars a year for individual/commercial license which obviously I can't afford. If you could help me out with a few questions, I would be really grateful of you!!!
1) When I apply for monetization, will I be asked whether I have commerical licenses of the aforementioned softwares by TH-cam?
2) If TH-cam doesn't ask for commercial licenses and after that my content is monetized, at what point can I expect these companies to send me a notice regarding the licenses? At 10k subscribers? 50k? 100k?
3) How much money do TH-camrs with 10-50k subscribers from 3rd world countries like India get monthly? Any idea?
4) Is it really worth it? I mean I do have the skills and knowledge but I honestly don't think I would be able to afford these softwares until and unless I start earning 500-1000$ per month via TH-cam.
Best
Thanks sir.