How to handle mupadmex error?

조회 수: 2 (최근 30일)
Niloufar 2022년 12월 27일
답변: Walter Roberson 2023년 1월 2일
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

답변 (2개)

Ajay Gajulapally
Ajay Gajulapally 2023년 1월 2일
The mupadmex error is caused because of your initial values of a, t0, alpha.
Consider Changing those values which resolves your mupadmex error.
a = 10;
t0 = 100;
alpha = 1000;

Walter Roberson
Walter Roberson 2023년 1월 2일
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.


Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기


Community Treasure Hunt

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

Start Hunting!

Translated by