how to do iteration starting with a known number

3 Ansichten (letzte 30 Tage)
mohamed
mohamed am 31 Mär. 2016
Beantwortet: Swastik Sarkar am 29 Mai 2025
hello i need to do an iteration process to obtain (pws) i have several variables that pws depend on and i need to know how to solve the problem here is a screenshot for the problem
<<
>> and all elements in the question are present like pts,tts,l and theta
thank you
  2 Kommentare
dpb
dpb am 31 Mär. 2016
What have you done so far?
mohamed
mohamed am 31 Mär. 2016
ok so far i got the first value but i dont know how to tell matlab to substitute with the new value of pws again

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Swastik Sarkar
Swastik Sarkar am 29 Mai 2025
Hi Mohammed,
I believe this can be approached in two ways depending on whether you want to manually iterate or use MATLAB's Optimization Toolbox.
The Manual implementation of the iteration logic in MATLAB is like this:
pws1 = pts + 0.25 * (pts/100) * (L * cos(theta))/100;
currentIteration = 0;
maxIterations = 100 % Some limit as the solution might not converge
while currentIteration < maxIterations:
Pavg = (pws1 + pts)/2; % pws1 is consumed here
% do the other calculations
% assign the new value of pws1
pws1 = newlyCalculatedValue
if(conditionMet):
break
end
end
Alternatively, if you're solving for pws such that it satisfies a fixed-point condition like pws = f(pws), you can use fsolve:
% Define the function to find the fixed point
f = @(pws) pws - someFunction(pws); % Goal: pws = someFunction(pws)
pws1 = pts + 0.25 * (pts/100) * (L * cos(theta))/100;
% Solve using fsolve
options = optimoptions('fsolve', 'Display', 'iter');
[pws_solution, fval, exitflag] = fsolve(f, pws1, options);
This is more elegant if your iteration is actually trying to solve an equation implicitly.
For more information on fsolve, refer the following MathWorks Documentation:
Hope this helps converge to the solution.

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by