I have an equation that relies on previous values to get the next.

6 views (last 30 days)
this is the basic set up i have
P=[1 2 3 4 5]
i need to solve for M2, then using M2 as the new M1, like so
P3/P2=(1+M3^2)/(1+M2^2), solve for M3
reiterate that process till i have all values of M in a matrix anbd plot them.

Answers (1)

Star Strider
Star Strider on 28 Sep 2022
I am not certain how the ‘P’ vector enters into this. If:
P1 = P(1) = 1
P2 = P(2) = 2
P3 = P(3) = 3
in this instance, then:
P = [1 2 3 4 5];
P2P1 = @(M1,M2) (1+M2.^2)./(1+M1.^2) - P(2)./P(1);
P3P2 = @(M2,M3) (1+M3.^2)./(1+M2.^2) - P(3)./P(2);
Pfcn = @(M1,M2,M3) [P2P1(M1,M2); P3P2(M2,M3)]
Pfcn = function_handle with value:
format long
Pv = fsolve(@(b)Pfcn(b(1),b(2),b(3)), [0; 1; 1])
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead.
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
Pv = 3×1
-0.000000009907974 1.000000000005345 1.414213562389785
Make appropriate changes to get the result you want.
Star Strider
Star Strider on 28 Sep 2022
I would like to help you with this.
I need you to describe step-by-step what you want to do.

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!