There is an error in calling the function in MATLAB, and the function itself can run 20

Updated on technology 2024-08-07
3 answers
  1. Anonymous users2024-02-15

    Because you don't know how many roots the equation has, so if you call it that way.

    x1 x2] = equation_solve(x,y,z);

    This means that the equation has two roots, and if there is only one root or none of them, then obviously x1 and x2 cannot be assigned to both.

    You can change it to call it like this.

    equation_solve(1,2,4);

  2. Anonymous users2024-02-14

    function [x1, x2] = equation_solve(a,b,c)

    delt = b*b - 4*a*c;

    if delt < 0

    there is no answer!!!'

    else if delt == 0

    there is only one answer '

    x1 = (-a+sqrt(delt))/2;

    ans = x1

    elsethere are two answers!!'

    x1 = (-a+sqrt(delt))/2;

    x2 = (-a-sqrt(delt))/2;

    ans = [x1 x2]

    endend

    There is no problem with the original file, and it is saved separately, which is equivalent to setting an algorithm yourself. Then you build another one. m file, write ** e.g. [x1 x2] = equation solve(1,2,1); When the system executes this line, it will call the above paragraph and output the result.

    Note: File names should be consistent when saving.

  3. Anonymous users2024-02-13

    The C++ compiler provided by MATLAB compiles M files into executable applications.

    Actions in MATLAB.

    1 No graph-related functions are used.

    Since the MATLAB compiler can only compile the function M file, if the original program is a script, it should be rewritten in the form of a function. Here are some examples:

    Create an m-file that reads as follows:

    function y = test1(n)y = 1 ;

    for i = 1 : n

    y = y * i ;

    end is compiled with the following command:"

    mcc –t –l cpp –h

    If the program consists of multiple M files, you only need to specify the main file in the compilation command, and MCC will automatically find the corresponding M file for compilation).

    After the compilation is complete, you will get the hpp and cpp files corresponding to the m file name, in this case the sum.

    2 Graph-related functions are used.

    Create an m-file that reads as follows:

    function test2

    plot(rand(10));

    Compile with the following command:

    mcc –p –b sglcpp

    If the program consists of multiple files, the treatment is the same as above).

    After compilation, we get the hpp and cpp files corresponding to the m file name, a main function file, two fig files in the bin directory, and an exe file. All we need is the hpp file corresponding to the M file, the cpp file, and the two fig files in the bin directory, in this case, and the sum in the bin directory.

    For more information, please visit

Related questions
2 answers2024-08-07

result love(boy, girl)if( boy.There is a room () and boyThere is a car (); >>>More

6 answers2024-08-07

Leave an email address and send it to you.

5 answers2024-08-07

mid(string a, start looking for the bit value (data b), find the number of digits (data c)) Your function looks like this. >>>More

9 answers2024-08-07

c=[20019894805 200210597876 2003121110898]; b=[200199988510 20021131018712 20031201158015]; a(1,:,=c;a(2,:,=b;As a hint, the above functions can be easily implemented with the mean sum find function: sum(sum())find(max()) can be nested

7 answers2024-08-07

The reading is correct, but the display of MATLAB only shows four decimal places, you can see the exact value by copying the data read into the workspace in MATLAB into XLS.