How to remove error form code.
Show older comments
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.
Answers (1)
Walter Roberson
on 5 Apr 2023
0 votes
taylor() accepts at most 3 positional parameters. In order to indicate the order of approximation you must use a name/value pair.
8 Comments
Syed
on 5 Apr 2023
Walter Roberson
on 5 Apr 2023
% 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
on 10 Apr 2023
Syed
on 14 Apr 2023
Syed
on 14 Apr 2023
Walter Roberson
on 14 Apr 2023
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
on 18 Apr 2023
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
