How to handle mupadmex error?
2 次查看(过去 30 天)
显示 更早的评论
I have a wave equation that is like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1244437/image.jpeg)
and here is the initial conditions:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1244442/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1244447/image.jpeg)
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 个评论
回答(2 个)
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;
0 个评论
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Code Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!