How to remove error form code.

Respected Sir/Maam.
I was trying to solve a Nonlinear System ODE by Differential transform method Pade approximation (DTM-PA). Hear It is error " Error using sym/taylor (line 104)" in File "shah (attached)" and "Undefined function 'padeApproximation' for input arguments of type 'symfun'" in file "Asad (attached)" and some errors, which i am not able to rectify. Can you please help. If any information is required, please feel free to ask.
Thanking you in Advance
you help will be highly apprecialbe.

Risposte (1)

Walter Roberson
Walter Roberson il 5 Apr 2023

0 voti

taylor() accepts at most 3 positional parameters. In order to indicate the order of approximation you must use a name/value pair.

8 Commenti

Syed
Syed il 5 Apr 2023
Humble Request sir
kindly edit the code, which you have marked the errors.
% Define the parameters
M_values = [0, 0.5, 1, 1.5, 2]; % Values of M for which we want to solve the ODE
% Loop over the different values of M
for i = 1:length(M_values)
M = M_values(i); % Current value of M
% Define the symbolic variables
syms f(eta) g(eta)
% Define the nonlinear ODEs
ode1 = diff(f, eta, 3) + f * diff(f, eta, 2) - (diff(f, eta))^2 - M * diff(f, eta) == 0;
ode2 = diff(g, eta) - 2 * diff(f, eta, 2) - 2 * f * diff(f, eta) == 0;
% Define the initial conditions
f0 = 0; % f(0) = 0
g0 = 0; % g(0) = 0
fp0 = 1; % f'(0) = 1
% Define the Padé approximations
p = 1; % Padé numerator degree
q = 1; % Padé denominator degree
% Obtain the Padé approximations for f and g
avars = sym('a', 1:p);
bvars = sym('b', 1:p);
f_pade = taylor(f, eta, 0, 'order', p) * (1 + sum(flip(avars) * (eta^q), 2));
g_pade = taylor(g, eta, 0, 'order', p) * (1 + sum(flip(bvars) * (eta^q), 2));
% Convert the Padé approximations into functions of eta
f_func = matlabFunction(f_pade, 'Vars', [eta, avars]);
g_func = matlabFunction(g_pade, 'Vars', [eta, bvars]);
% Generate data for plotting
eta_vals = linspace(0, 10, 1000); % Values of eta for which we want to evaluate f and g
f_vals = f_func(eta_vals);
g_vals = g_func(eta_vals);
% Plot f and g for the current value of M
figure;
plot(eta_vals, f_vals, 'b', 'LineWidth', 1.5);
hold on;
plot(eta_vals, g_vals, 'r', 'LineWidth', 1.5);
legend('f(eta)', 'g(eta)');
title(['M = ', num2str(M)]);
xlabel('eta');
ylabel('f(eta), g(eta)');
grid on;
end
However, this is not going to work:
  • you have not defined any function f or g to be able to evaluate after you have done matlabFunction()
  • you have not defined any a1 or b1 values and do not try to pass any additional parameters.
If you were to create symbolic functions instead of using matlabFunction then you could get something that you could evaluate using f_func() and g_func() -- but the results would be in terms of the a* and b* variables, and so would be something you would not be able to plot.
Syed
Syed il 10 Apr 2023
Revered Sir,
Hope you are doing well.
I would like to draw your worthy attention towards error on ODE's with Boundary Conditions (attached).
f and g are define in Boundary conditions
a1 and b1 are define pade approximations p=1 and q=1 or p=2 and q=2
where p denote the numerator degree and q denote denominator degre.
Pade Approximants (PA) are a family of rational functions used to approximate a given function by matching the Taylor series expansion of the function up to a certain order. Pade approximants are widely used in numerical analysis and applied mathematics because they can provide very accurate approximations with a relatively small number of terms in the series.
The general form of a Pade approximant of order (p, q) for a function f(x) is given by:
f(x) ≈ R(x) = (a_0 + a_1 x + a_2 x^2 + ... + a_p x^p) / (1 + b_1 x + b_2 x^2 + ... + b_q x^q)
where the coefficients a_i and b_i are determined by matching the Taylor series expansion of f(x) up to order p+q.
To formulate the PA, we first expand the function f(x) as a Taylor series:
f(x) = a_0 + a_1 x + a_2 x^2 + ... + a_n x^n + O(x^(n+1))
Then we substitute this expansion into the general form of the Pade approximant and match the coefficients of like powers of x. This results in a set of linear equations that can be solved for the coefficients a_i and b_i. The resulting Pade approximant is then used as an approximation for the original function f(x).
I tried my level best but all in vain.
I humbly request your honor to remove the error and solve the said issue.
I would be very helpfull for your help.
Thank you ahead of time.
Syed
Syed il 14 Apr 2023
sir @Walter Roberson, i am waiting for your response
p = 1; q = 2;
syms a0 b0 x
syms a [1 p]
syms b [1 q]
a = [a0 a];
b = [b0 b];
n = sum(a .* x.^(0:p))
n = 
d = sum(b .* x.^(0:q))
d = 
f(x) = n / d
f(x) = 
You will probably want to look at coeffs for matching coefficients. And you might possibly need numden
Syed
Syed il 14 Apr 2023
yes sir @Walter Roberson and also plot the grahp for given ODE with Boundary conditions by using Differential transform method
Sorry, I am not willing to learn Differential Transform Method at this time. I am a bit distracted by other things, so ask specific short questions and I might answer, but I am not willing to go through the mathematics of what you are trying to do.
I have shown you how to construct the rational polynomial, and shown you the command needed to match coefficients; you can work from there.
Syed
Syed il 18 Apr 2023
Humble Request sir
Sir i need series solution graph (eq 10 and 17) and attach the file in PDF form (all details are disussed in PDF File)
I humbly request your honor to solve the said issue.
I would be very helpfull for your help.
Thank you ahead of time.

Accedi per commentare.

Richiesto:

il 5 Apr 2023

Commentato:

il 18 Apr 2023

Community Treasure Hunt

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

Start Hunting!

Translated by