how to do iteration starting with a known number

조회 수: 3 (최근 30일)
mohamed
mohamed 2016년 3월 31일
답변: Swastik Sarkar 2025년 5월 29일
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
dpb
dpb 2016년 3월 31일
What have you done so far?
mohamed
mohamed 2016년 3월 31일
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

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

답변 (1개)

Swastik Sarkar
Swastik Sarkar 2025년 5월 29일
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.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by