How to Define a Symbolic Continued Fraction
33 visualizzazioni (ultimi 30 giorni)
Maximilian Schönau il 2 Gen 2021
Hello, I want to create and simplify a symbolic fraction, but dont now how. My fraction has the following form:
I want to repeat that fraction for n times, with beeing symbolic Variables, to work with and maybe simplify the function (or similar functions).
It seems to me now, that the question I want the answer to is:
Is it possible to define and simplify a function in MATLAB which form depends on a parameter?
The function above has no fixed form, since the repetitions of depend on n, which shall be and stay a symbolic variable. In the end I would like a simplified form of . This may not be possible with the function I gave as an example here, but this is not the first time I had this problem, and I would be really glad if there is something I can do here... :)
I dont know if this is possible in MATLAB, two things would help me to find a way:
- Is there a way to have recursion in symbolic functions? I want to define something like:
syms f(n) n x
f(n) = 1/f(n-1) + x; % Example of recursion in a function
this does not result in an error but does also not return the solution when I substitue n with a numeric value.
- Is there a smart way to define the fraction above with n beeing not a symbolic variable? I could print my fraction n times in a string, and convert that string to a symbolic function, but that does not seem smart to me...
Più risposte (2)
David Hill il 3 Gen 2021
Modificato: David Hill il 3 Gen 2021
function L = continuedFraction(N,n)
syms A B;
Run the function for the number of times (n) you want, then add in A/N and simplify.
syms A B;