# How to handle mupadmex error?

4 vues (au cours des 30 derniers jours)
Niloufar le 27 Déc 2022
I have a wave equation that is like this:
and here is the initial conditions:
I should create the gif for a variety of c but I get mupadmex error Which I don't know how to fix and here is my code:
clear;clc;close all;
a = 1;
t0 = 1;
alpha = 1;
syms x;
%define lambda function
f = @(x) ((-a/t0)*x-a)*(x>-2*t0-0.1 & x<-t0) + ((a/t0)*x+a)*(x>-t0 & x<=0) + ((-a/t0)*x+a)*(x>0 & x<t0) + ((a/t0)*x-a)*(x>t0 & x<2*t0+0.1);
g = @(x) alpha.*f(x);
for c = 0:0.05:1
h(x) = int(g(x));
G = matlabFunction(h);
desired_fun = G(x+c) - G(x-c);
my_plot = fplot(((f(x-c) + f(x+c))/2) + desired_fun,[-t0 t0]);
frame = getframe(1);
im = frame2im(frame); %pause(0.01);
[imind,cm] = rgb2ind(im,256);
imwrite(imind,cm,"C:\Users\ernika\wave_equation.gif",'gif','WriteMode','append'); %saved as mygif1
drawnow;
if(c~=1)
delete(my_plot)
end
end
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (2)

Ajay Gajulapally le 2 Jan 2023
The mupadmex error is caused because of your initial values of a, t0, alpha.
a = 10;
t0 = 100;
alpha = 1000;
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Walter Roberson le 2 Jan 2023
Do not define the functions that way. The symbolic toolbox does not define a result for multiplying a symbolic expression by a logical value.
You need to define the function symbolically using piecewise. Then integrate it with a definite integral specifying the variable of integration and the upper and lower bound. You can make a bound the variable of integration if you need to.
Then use matlabFunction with the 'file' option and with 'optimize' off. You must use 'file' for this purpose. 'file' option is able to generate code for piecewise.
Now, the function that results is not vectorized, so if you try to use it in a context such as integral() or fplot() then that will fail; you would need an arrayfun wrapper in such cases.
You appear to be passing symbolic x back into the result of matlabFunction, but that is going to fail.
I would suggest that you reconsider using matlabFunction and use
G = h;
which will avoid the issues about code generation and will allow a proper desired_function to be defined symbolically.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Code Generation dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by