Tag Archives: matlab

After matlab2017b is activated, open the error reporting license manager error – 8

When installing, I read the tutorial and said that after activation, I need to crack the dynamic library file under the “crack” folder“ libmwservices.dll ”Replace it with “r2015b/bin/win64” under the installation directory of MATLAB 2015b\ libmwservices.dll ”

But I don’t have it in my crack file libmwservices.dll File… It’s strange that I downloaded the crack file again, but it’s still the same… Maybe it’s a version problem
or not

Finally, a practical method is found in another blog https://blog.csdn.net/m0_ 37638031/article/details/78982498

This blog contains not only the installation package of MATLAB, but also detailed and practical tutorials, especially the last step after activation

The specific steps are as follows:

After activation, copy the netapi32.dll file under the crack file (path as follows: MATLAB r2017b win64 crack/r2017b/bin/win64/netapi32.dll) directly to the installed matlab file (path as follows: C:// program files/Matlab/r2017b/bin/win64).

And then it’s working.

Matlab prompt error

Enter the following code
(1)

a = [1 2;3 4];
a(6) = 7;

Prompt:
attempt to grow array along ambiguous dimension.
in Chinese:
attempt to grow large array along fuzzy dimension

The following codes are correct
(2)

a = [1 2;3 4];
a(5, 8) = 7;

Why is it that code (1) is wrong and code (2) is at a loss when it exceeds the predefined matrix size?

The cause of the problem is as indicated in the prompt

, the program cannot determine the dimension of the matrix.
What do you mean?
Although the code segment (2) exceeds the predefined matrix dimension: 2-by-2, it can determine the matrix dimension after an assignment (a (5, 8) = 7): 5-by-8.
The code segment (1) is a linear index -- 6, which is converted to a matrix subscript of 2-by-3 or 3-by-2??
The computer doesn't know, so it reports an error. " attempts to grow data along fuzzy dimensions ". This tip, feel very awkward, in fact, is very correct .

How to use matlab to solve equation

How to use matlab to solve equation

1. Preface

As one of the three major mathematical software, Matlab is the best in numerical calculation. Solving equations is the most basic and common problem in engineering study and engineering calculation. It is very important to master the method of solving equations with modern tools to improve our engineering literacy. Therefore, this paper will introduce the method of solving equations in MATLAB.

2. Usage

solving process

2.1 – indicated variables

Tell the computer the variables contained in the equation, including parameters and unknown variables. For example, the equation to be solved is: obviously, there are symbolic variables a, B, C and X in the equation, so the writing method of this step is:

syms a b c x  

 

2.2 specify equations, unknowns and constraints (not required)

If there is more than one equation,

eqns put it in [] and separate it with a comma. For example:
vars unknowns to be solved
Names value (not required) Names: “return conditions” returns the general solution with parameters. ” If ‘true’ is returned and ‘false’ is not, a special solution is given;
Name: ‘ignoreanalytical constraints’ is the simplest form of the solution given. ‘true ‘is yes and’ false ‘is no
Name:’ principalvalue ‘only gives one solution. False is to return all solutions, true is to return only one solution;
Name: ‘real’ only returns real solutions

2.3 obtain the solution of the equation

If there are multiple functions, the solution is stored as a structure.

 

3. Specific examples

3.1 = general solution of sin (x) = 1

 

Specific code:

syms x  [x,params,conds]=solve(sin(x)==1,’ReturnConditions’, true) 

 

result

solx =pi/2+2*pi*k  params =k  conds =in(k,’integer’)

 

It can be seen that the general solution of the equation is as follows:

 

3.2 solve the following equation:

code:

syms a b c y x [x,y]=solve([a*x^2+b*y+c==0,a*x+2*y==4],[x,y])

 

result:

x =  ((a*b)/4-(-(a*(- a*b^2+32*b +16*c))/16)^(1/2))/a  ((a*b)/4+(-(a*(- a*b^2+32*b +16*c))/16)^(1/2))/a   y =  (-(a*(- a*b^2+32*b +16*c))/16)^(1/2)/2-(a*b)/8+2  2-(-(a*(- a*b^2+32*b +16*c))/16)^(1/2)/2-(a*b)/8

 

Namely:

Solving equations and equations with MATLAB

1. Solve function

① Numerical solution of single equation

syms x;

x0 = double(solve(x +2 – exp(x),x));

Find the solution of X + 2 = exp (x), and the result is shown in double

In use, you can also write x + 2 = = exp (x), note that ‘= =’

In addition, if there are multiple solutions, the function returns only one solution

② Solving the equation with signed variables

syms x a b c;

x0 = solve(a*x^2+b*x+c,x);

Two solutions can be obtained

③ Solving equations

syms x y z;

e1 = 2*x – y +z;

e2 = x + y – 6;

e3 = z^2 +2*y;

[x0,y0,z0] = solve(e1,e2,e3,x,y,z);

double([x0,y0,z0])

Can return multiple solutions, note that can not directly solve double conversion

2. Vpasolve function

Only one solution can be returned to solve the equation in a certain range

syms x;

double(vpasolve(x +2 – exp(x),x,[-2,2]))

The solution near a point can also be obtained

double(vpasolve(x +2 – exp(x),x,1))

The premise is that this’ nearby point ‘cannot deviate too much from the solution

To find out all the solutions, we can first draw a graph and find out the approximate interval or adjacent points of each solution

The usage of several integer functions in MATLAB (fix, floor, ceil, round)

There are the following integer functions in Matlab: fix, floor, ceil, round, and their differences are as follows


Fix: round in the direction of 0

>>fix(2.8) = 2
>>fix(-2.8) = -2

Floor: round in the direction of negative infinity

>>floor(2.8) = 2
>>floor(-2.8) = -3

Ceil: round in the direction of positive infinity

>>ceil(2.8) = 3
>>ceil(-2.8) = -2

Round: round to the nearest integer

>>round(2.8) = 3
>>round(-2.8) = -3

Solutions to several VTK compilation errors (vtk5.8 + VS2010)

There are several common errors that can occur during the compilation of a VTK project. The solutions are as follows:
error 1:
fatal error C1189: #error : This file requires _WIN32_WINNT to be #defined at least to 0x0403
cause:
The minimum version of the system set for version migration is too low
Visual C++ 2010 no longer supports targeting Windows 95, Windows 98, Windows ME, or Windows NT. If your WINVER or _WIN32_WINNT macros are assigned to one of these versions of Windows, you must modify the macros. When you upgrade a project that was created by using an earlier version of Visual C++, You may see compilation errors related to the WINVER or _WIN32_WINNT macros if they are assigned to a version of Windows that is no longer supported (From MSDN)
The immediate cause – there are three lines of code in atlcore.h:
#if _WIN32_WINNT < 0x0403
#error This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x0501 or higher is recommended.
#endif
> bbb>
All in VTK directory stdafx. H file reference to modify WINVER, http://msdn.microsoft.com/en-us/library/aa383745.aspx _WIN32_WINNT, _WIN32_WINDOWS and _WIN32_IE definition, for example: # define WINVER 0 x0501
 


error 2:
error C2371: ‘char16_t’ : redefinition
:
In VTK project files are generated in the process of choosing the Matlab support (tex-mex), and adopted the VS2010 and above programming environment (http://connect.microsoft.com/VisualStudio/feedback/details/498952/vs2010-iostream-is-incompatible-with-matlab-matrix-h) :
I looked at the source code for matrix.h < core/matlab/include/matrix.h>
It has a definition for char16_t
typedef char16_t char16_t;” . Also the C++ header “Microsoft Visual Studio 10.0\VC\ Include \ YVALS. H “Also defines the same identifier(CHAR16_T). Because of these two definitions we get the redefinition error when matrix iostream.h(it internally includes yvals.h) are included in some cpp file.
Declaration of char16_t in the yvals.h is newly introduced in dev10 and was not there in VS2008. Therefore you are getting this redefinition error now on VS 2010(Dev10).

> solution 1 (without follow-up test) : BBB>
//added by John for solving conflict with VS2010
#if (_MSC_VER) < 1600 //VS2010
# ifndef __STDC_UTF_16__
# ifndef CHAR16_T
# if defined(_WIN32) & & defined(_MSC_VER)
# define CHAR16_T wchar_t
# else
# define CHAR16_T UINT16_T
# endif
typedef CHAR16_T char16_t;
# endif
#endif
#else
#include < yvals.h>
#endif//VS2010
> solution 2 (without follow-up test) : BBB>
Rename all char16_t in matrix.h
 
error 3:
LNK4199: /DELAYLOAD:vtkIO.dll ignored; no imports found from vtkIO.dll
cause:
DelayLoad (selected from the in-depth analysis DelayLoad “http://blog.csdn.net/panda1987/article/details/5936770).
As we know, there are two basic methods of DLL loading: implicit loading and explicit loading. Implicit loading is the method introduced in the previous article, where the input table of a PE loads the DLL into the memory space before entering the entry function. Explicit loading uses methods like LoadLibrary and GetProAddress to load the DLL into the process space when needed. Both of these methods are the ones we use most often. So what is delay load?
A DLL designated as Delay Load will not actually load the process space until it is needed, which means that the DLL will not be loaded if no function located in the DLL is called. The loading process is done by LoadLibrary and GetProcAddress, which is, of course, transparent to the programmer.
What are the benefits of this?There is no doubt that the program starts faster, because many DLLs may not be used at startup. Even some DLLs may not be used in the entire life cycle, so with Delay Load, the DLL does not need any memory.
> bbb>
Because for dynamic libraries, the load information is still recorded in the corresponding lib file, so in the properties of the project Linker->; Input-> Additional Depandencies may also have #pragma comment(lib, “vtkio. lib”) at the beginning of the Cpp. If the file is not found by the compile prompt, it is also required in the Linder->; General-> Add the location of the file in the Additional Library Directory.
If someone is the difference between the Lib and Dll unclear, see: http://www.cppblog.com/amazon/archive/2011/01/01/95318.html

Reproduced in: https://www.cnblogs.com/johnzjq/archive/2011/12/14/2287823.html

Matlab draw logarithmic coordinates!

In many engineering problems, some characteristics of data can be seen more clearly through logarithmic transformation of data. The curve of data points depicted in logarithmic coordinate system can directly represent logarithmic transformation.
There are two kinds of logarithmic transformation: double logarithmic transformation and single axis logarithmic transformation. Loglog function can be used to achieve the double log coordinate transformation, semilogx and Semilogy functions can be used to achieve the single axis log coordinate transformation.
Loglog (Y) means that the x and Y coordinates are logarithmic coordinates
Semilogx (Y) means that the x axis is a logarithmic coordinate system
Semilogy (…). That means that the Y-axis is a logarithmic coordinate system
So plotyy has two y axes, one on the left and one on the right
Example 1: Create a simple loglog with the square tag.
Solution: Enter a command
X = logspace (1, 2);
loglog(x,exp(x),’-s’)
Grid on % annotated grid
The produced figure is:

Example 2: Create a simple semi-logarithmic graph.
Solve input command:
x=0:.1:10;
semilogy(x,10.^x)
The produced figure is:

example 3: draw function graph, logarithmic graph and semilogarithmic graph of y=x^3.
Solution: Enter in the window:
x=[1:1:100];
Subplot (2,3,1);
plot(x,x.^3);
grid on;
title ‘plot-y=x^3’;
 
Subplot (2, 31);
loglog(x,x.^3);
grid on;
title ‘loglog-logy=3logx’;
 
Subplot (2 filling);
plotyy(x,x.^3,x,x);
grid on;
title ‘plotyy-y=x^3,logy=3logx’;
 
Subplot (2, 4);
semilogx(x,x.^3);
grid on;
title ‘semilogx-y=3logx’;
 
Subplot (2,3,5);
semilogy(x,x.^3);
grid on;
title ‘semilogy-logy=x^3’;
The produced figure is:

 

Empty Matrices, Scalars, and Vectors

Overview
Although matrices are two dimensional, they do not always appear to have a rectangular shape. A 1-by-8 matrix, for example, has two dimensions yet is linear. These matrices are described in the following sections:
The Empty Matrix An empty matrix has one or more dimensions that are equal to zero. A two-dimensional matrix with both dimensions equal to zero appears in the MATLAB® application as []. The expression A = [] assigns a 0-by-0 empty matrix to A. Scalars A scalar is 1-by-1 and appears in MATLAB as a single real or complex number (e.g., 7, 583.62, -3.51, 5.46097e-14, 83+4i). Vectors A vector is 1-by-n or n-by-1, and appears in MATLAB as a row or column of real or complex numbers:

     Column Vector                 Row Vector

         53.2                  53.2 87.39 4-12i 43.9
         87.39
         4-12i
         43.9

The Empty Matrix
A matrix having at least one dimension equal to zero is called an empty matrix. The simplest empty matrix is 0-by-0 in size. Examples of more complex matrices are those of dimension 0-by-5 or 10-by-0.
To create a 0-by-0 matrix, use the square bracket operators with no value specified:

A = [];

whos A
  Name      Size            Bytes  Class     Attributes

  A         0x0                 0  double 

You can create empty matrices (and arrays) of other sizes using the zeros, ones, rand, or eye functions. To create a 0-by-5 matrix, for example, use

A = zeros(0,5)
A =

  0×5 empty double matrix
Operating on an Empty Matrix

The basic model for empty matrices is that any operation that is defined for m-by-n matrices, and that produces a result whose dimension is some function of m and n, should still be allowed when m or n is zero. The size of the result of this operation is consistent with the size of the result generated when working with nonempty values, but instead is evaluated at zero.
For example, horizontal concatenation

C = [A B]

requires that A and B have the same number of rows. So if A is m-by-n and B is m-by-p, then C is m-by-(n+p). This is still true if m, n, or p is zero.
As with all matrices in MATLAB, you must follow the rules concerning compatible dimensions. In the following example, an attempt to add a 1-by-3 matrix to a 0-by-3 empty matrix results in an error:

[1 2 3] + ones(0,3)
Error using +
Matrix dimensions must agree.

Common Operations.   The following operations return zero on an empty array:

A = [];
size(A), length(A), numel(A), any(A), sum(A)

These operations return a nonzero value on an empty array :

A = [];
ndims(A), isnumeric(A), isreal(A), isfloat(A), isempty(A), ...
   all(A), prod(A)
Using Empty Matrices in Relational Operations

You can use empty matrices in relational operations such as “equal to” (==) or “greater than” (>) as long as both operands have the same dimensions, or the nonempty operand is scalar. The result of any relational operation involving an empty matrix is the empty matrix. Even comparing an empty matrix for equality to itself does not return true, but instead yields an empty matrix:

x = ones(0,3);
y = x;

y == x
ans =

  0×3 empty logical array
Using Empty Matrices in Logical Operations

MATLAB has two distinct types of logical operators:
Short-circuit (&&, ||) — Used in testing multiple logical conditions (e.g., x >= 50 && x < 100) where each condition evaluates to a scalar true or false. Element-wise (&, |) — Performs a logical AND, OR, or NOT on each element of a matrix or array.
Short-circuit Operations.   The rule for operands used in short-circuit operations is that each operand must be convertible to a logical scalar value. Because of this rule, empty matrices cannot be used in short-circuit logical operations. Such operations return an error.
The only exception is in the case where MATLAB can determine the result of a logical statement without having to evaluate the entire expression. This is true for the following two statements because the result of the entire statements are known by considering just the first term:

true || []
ans =

  logical

   1

false && []
ans =

  logical

   0

Element-wise Operations.   Unlike the short-circuit operators, all element-wise operations on empty matrices are considered valid as long as the dimensions of the operands agree, or the nonempty operand is scalar. Element-wise operations on empty matrices always return an empty matrix:

true | []
ans =

  0×0 empty logical array

Note   This behavior is consistent with the way MATLAB does scalar expansion with binary operators, wherein the nonscalar operand determines the size of the result.

Scalars
Any individual real or complex number is represented in MATLAB as a 1-by-1 matrix called a scalar value:

A = 5;

ndims(A)        % Check number of dimensions in A
ans =
     2

size(A)         % Check value of row and column dimensions
ans =
     1     1

Use the isscalar function to tell if a variable holds a scalar value:

isscalar(A)
ans =

  logical

   1

Vectors

Matrices with one dimension equal to one and the other greater than one are called vectors. Here is an example of a numeric vector:

A = [5.73 2-4i 9/7 25e3 .046 sqrt(32) 8j];

size(A)         % Check value of row and column dimensions
ans =
     1     7

You can construct a vector out of other vectors, as long as the critical dimensions agree. All components of a row vector must be scalars or other row vectors. Similarly, all components of a column vector must be scalars or other column vectors:

A = [29 43 77 9 21];
B = [0 46 11];

C = [A 5 ones(1,3) B]
C =
   29   43   77    9   21    5    1    1    1    0   46   11

Concatenating an empty matrix to a vector has no effect on the resulting vector. The empty matrix is ignored in this case:

A = [5.36; 7.01; []; 9.44]
A =
    5.3600
    7.0100
    9.4400

Use the isvector function to tell if a variable holds a vector:

isvector(A)
ans =

  logical

   1