Error while converting a HUGE symbolic equation to double

  • Thread starter sgvaibhav
  • Start date
  • Tags
    Error
In summary: This will eliminate the need for you to copy and paste the equations every time you want to plot the graph. In summary, to simplify your code and make it more efficient, you should use the vpa function to convert your symbolic equations into double precision values that can be used for plotting.
  • #1
sgvaibhav
68
0
Hi.
I will try to simplify my question to make it clear.

I perform huge calculations worth 70 lines. Beginning by syms x and y.

I get two functions/paramters 'Wnet' and 'SFC' in terms of x and y (VERY HUGE EQUATION)Now i want to plot a very complicated 2D graph.

The script below allows me to plot in 2D but for that, i have to first run first script, get Wnet and SFC and then copy the values and make another function in another script to plot.

Code:
clear
for i=1:6;
    
    x(i)=5.*i;
    
    for j=1:5;
        
        y(j)=1000+(100*j);
                        
        %i  ran the first script, copied this from output and pasted here
        x1(i,j)=(99.*((57443.*((4018.*y(j).*(66875./(57036.*x(i))).^(2528214091580831./18014398509481984))./5 - (57443.*y(j))./50 + (2894969.*x(i).^(200./623))./50))./(50.*((57443.*y(j))./50 - 41160000)) + 57443./50).*(y(j) - y(j).*(66875./(57036.*x(i))).^(2528214091580831./18014398509481984)))./100 + (99.*(y(j) - y(j).*(66875./(57036.*x(i))).^(2528214091580831./18014398509481984)).*((57443.*((4018.*y(j).*(66875./(57036.*x(i))).^(2528214091580831./18014398509481984))./5 - (57443.*y(j))./50 + (2894969.*x(i).^(200./623))./50))./(50.*((57443.*y(j))./50 - 41160000)) - (57443.*((57443.*y(j))./50 - (57443.*y(j).*(66875./(57036.*x(i))).^(2528214091580831./18014398509481984))./50))./(50.*((57443.*y(j))./50 - 41160000)) + 57443./50))./100 - (2894969.*x(i).^(200./623))./10 + 2894969./10;

          % i copied this from output of first script and pasted here
        y1(i,j)=-(((57443.*y(j))./50 - (57443.*y(j).*(66875./(57036.*x(i))).^(2528214091580831./18014398509481984))./50)./((57443.*y(j))./50 - 41160000) - ((4018.*y(j).*(66875./(57036.*x(i))).^(2528214091580831./18014398509481984))./5 - (57443.*y(j))./50 + (2894969.*x(i).^(200./623))./50)./((57443.*y(j))./50 - 41160000))./((99.*((57443.*((4018.*y(j).*(66875./(57036.*x(i))).^(2528214091580831./18014398509481984))./5 - (57443.*y(j))./50 + (2894969.*x(i).^(200./623))./50))./(50.*((57443.*y(j))./50 - 41160000)) + 57443./50).*(y(j) - y(j).*(66875./(57036.*x(i))).^(2528214091580831./18014398509481984)))./100 + (99.*(y(j) - y(j).*(66875./(57036.*x(i))).^(2528214091580831./18014398509481984)).*((57443.*((4018.*y(j).*(66875./(57036.*x(i))).^(2528214091580831./18014398509481984))./5 - (57443.*y(j))./50 + (2894969.*x(i).^(200./623))./50))./(50.*((57443.*y(j))./50 - 41160000)) - (57443.*((57443.*y(j))./50 - (57443.*y(j).*(66875./(57036.*x(i))).^(2528214091580831./18014398509481984))./50))./(50.*((57443.*y(j))./50 - 41160000)) + 57443./50))./100 - (2894969.*x(i).^(200./623))./10 + 2894969./10);
        
        x2=x1';
        y2=y1';
                
    end
    
end
plot(x1,y1,x2,y2)

This works, However this code is very inconvenient since i have to copy the big output from first script, change x to x(i), y to y(j), * to .* , / to ./ and ^ to .^ and then i have to paste to second script to plot the graph.Instead i combined to make one big script to directly plot the graph (trying to convert the symbolic equation into double), however i get an error to convert symbolic equation to double. Here is is the second half of the big code, which has the error.

Code:
%internal memory from computing the last 70 lines
% (stored internally) Wnet=(99*((57443*((4018*y*(66875/(57036*x))^(2528214091580831/18014398509481984))/5 - (57443*y)/50 + (2894969*x^(200/623))/50))/(50*((57443*y)/50 - 41160000)) + 57443/50)*(y - y*(66875/(57036*x))^(2528214091580831/18014398509481984)))/100 + (99*(y - y*(66875/(57036*x))^(2528214091580831/18014398509481984))*((57443*((4018*y*(66875/(57036*x))^(2528214091580831/18014398509481984))/5 - (57443*y)/50 + (2894969*x^(200/623))/50))/(50*((57443*y)/50 - 41160000)) - (57443*((57443*y)/50 - (57443*y*(66875/(57036*x))^(2528214091580831/18014398509481984))/50))/(50*((57443*y)/50 - 41160000)) + 57443/50))/100 - (2894969*x^(200/623))/10 + 2894969/10;
% (stored internally) SFC=-(((57443.*y)./50 - (57443.*y.*(66875./(57036.*x)).^(2528214091580831./18014398509481984))./50)./((57443.*y)./50 - 41160000) - ((4018.*y.*(66875./(57036.*x)).^(2528214091580831./18014398509481984))./5 - (57443.*y)./50 + (2894969.*x.^(200./623))./50)./((57443.*y)./50 - 41160000))./((99.*((57443.*((4018.*y.*(66875./(57036.*x)).^(2528214091580831./18014398509481984))./5 - (57443.*y)./50 + (2894969.*x.^(200./623))./50))./(50.*((57443.*y)./50 - 41160000)) + 57443./50).*(y - y.*(66875./(57036.*x)).^(2528214091580831./18014398509481984)))./100 + (99.*(y - y.*(66875./(57036.*x)).^(2528214091580831./18014398509481984)).*((57443.*((4018.*y.*(66875./(57036.*x)).^(2528214091580831./18014398509481984))./5 - (57443.*y)./50 + (2894969.*x.^(200./623))./50))./(50.*((57443.*y)./50 - 41160000)) - (57443.*((57443.*y)./50 - (57443.*y.*(66875./(57036.*x)).^(2528214091580831./18014398509481984))./50))./(50.*((57443.*y)./50 - 41160000)) + 57443./50))./100 - (2894969.*x.^(200./623))./10 + 2894969./10);

for i=1:6;
    
    x(i)=5.*i;
    
    for j=1:5;
        
        y(j)=1000+(100*j);
                        
        x1=double(Wnet);              %THE ERROR CODE
        y1=double(SFC);                %THE ERROR CODE
        
        x2=x1';
        y2=y1';
                        
    end
    
end
plot(x1,y1,x2,y2)

However when i run this, i get the error

? Error using ==> mupadmex
Error in MuPAD command: DOUBLE cannot convert the input expression into a double array.

If the input expression contains a symbolic variable, use the VPA function instead.

Error in ==> sym.sym>sym.double at 936
Xstr = mupadmex('symobj::double', S.s, 0);

Error in ==> Working at 14
x1=double(Wnet);
Help me =)

If you are still confused with the question, let me know, i will try to clarify it more.
 
Physics news on Phys.org
  • #2
The answer to your question is to use the "vpa" function instead of the "double" function. The vpa function can be used to convert symbolic equations into double-precision values that can be used for plotting. For example, you can use the following code to convert your Wnet and SFC equations into double precision values: x1 = vpa(Wnet);y1 = vpa(SFC);You can then use the x1 and y1 values to plot your graph.
 

Related to Error while converting a HUGE symbolic equation to double

1. What does it mean when I get an error while converting a symbolic equation to double?

When you receive an error while converting a symbolic equation to double, it means that there is a problem with the conversion process. This could be due to a variety of reasons, such as the equation being too large or complex for the conversion algorithm to handle.

2. Why does the error occur when converting a HUGE symbolic equation to double?

The error occurs when converting a HUGE symbolic equation to double because the conversion algorithm has limitations in terms of the size and complexity of the equation it can handle. When the equation is too large or complex, the algorithm may encounter issues and produce errors.

3. How can I fix the error while converting a HUGE symbolic equation to double?

There are a few potential solutions to fixing the error while converting a HUGE symbolic equation to double. One option is to break down the equation into smaller, simpler parts and convert them individually. Another option is to use a different conversion algorithm or software that may be better equipped to handle larger and more complex equations.

4. Is there a limit to the size or complexity of an equation that can be converted to double without errors?

Yes, there is a limit to the size and complexity of an equation that can be converted to double without encountering errors. This limit may vary depending on the conversion algorithm or software being used. It is always best to check the documentation or contact the developer for more information on the limitations of a particular conversion tool.

5. Can I avoid errors when converting a HUGE symbolic equation to double?

While it is not always possible to completely avoid errors when converting a HUGE symbolic equation to double, there are some steps you can take to minimize the chances of encountering errors. These include simplifying the equation as much as possible, using a robust and efficient conversion algorithm or software, and ensuring that your computer has enough memory and processing power to handle the conversion process.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Programming and Computer Science
Replies
4
Views
968
  • Programming and Computer Science
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Differential Equations
Replies
1
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top