Question

In: Electrical Engineering

q1) using Matlab make a code that allows a user to enter a function like fractional...

q1) using Matlab make a code that allows a user to enter a function like fractional function and cubic liner function then the Matlab send a domain, range, continuity

Solutions

Expert Solution


Before you use any MATLAB Compiler element, initialize the supporting libraries with the current example of Microsoft® Excel®. Do this once for an Excel session that makes use of the MATLAB Compiler components.
To do this initialization, name the utility library operate MWInitApplication, which is a member of the MWUtil class. This class is part of the MWComUtil library. See classification MWUtil .
A method so as to add this initialization code into a VBA module is to provide a subroutine that does the initialization once, and effectively exits for all subsequent calls. The next Microsoft visual basic® code sample initializes the libraries with the present instance of Excel. A global variable of form Object named MCLUtil holds an instance of the MWUtil type, and one other world variable of style Boolean named bModuleInitialized retailers the reputation of the initialization approach. The personal subroutine InitModule() creates an instance of the MWComUtil type and calls the MWInitApplication method with an argument of software. Once this function succeeds, all subsequent calls exit with out reinitializing.
Dim MCLUtil As Object
Dim bModuleInitialized As Boolean
private Sub InitModule()
If no longer bModuleInitialized Then
On Error GoTo Handle_Error
If MCLUtil Is Nothing Then
Set MCLUtil = CreateObject("MWComUtil.MWUtil")
finish If
call MCLUtil.MWInitApplication(utility)
bModuleInitialized = actual
Exit Sub
Handle_Error:
bModuleInitialized = False
end If
end Sub
This code is just like the default initialization code generated within the VBA module created when the component is constructed. Each and every operate that uses MATLAB Compiler add-ons can include a call to InitModule at
the establishing to be certain that the initialization constantly will get carried out as needed.
Create an instance of a class
Overview
CreateObject operate
New Operator
How the MATLAB Runtime Is Shared amongst classes
Overview
earlier than calling a category system (compiled MATLAB operate), you need to create an illustration of the category that comprises the approach. VBA presents two strategies for doing this:
CreateObject operate
New operator
CreateObject perform
This method makes use of the Microsoft visual normal utility programming interface (API) CreateObject perform to create an example of the class. Microsoft refers to calling CreateObject as late binding and using new as early binding.
To use this process, declare a variable of form Object utilizing Dim to hold a reference to the class example and make contact with CreateObject utilizing the class programmatic identifier (ProgID) as an argument, as shown within the subsequent illustration:
perform foo(x1 As Variant, x2 As Variant) As Variant
Dim aClass As Object

On Error Goto Handle_Error
Set aClass = CreateObject("mycomponent.Myclass.1_0")
' (name some approaches on aClass)
Exit perform
Handle_Error:
foo = Err.Description
end function
New Operator
This procedure uses the visible general New operator on a variable explicitly dimensioned as the class to be created. Earlier than utilising this method, you have got to reference the kind library containing the category in the current VBA undertaking. Do that through settling on the instruments menu from the visible general Editor, after which identifying References to show the on hand References record. From this list, decide on the necessary form library.
The next instance illustrates using the brand new operator to create a class example. It assumes that you've got selected mycomponent 1.0 form Library from the on hand References list earlier than calling this function.
Operate foo(x1 As Variant, x2 As Variant) As Variant
Dim aClass As mycomponent.Myclass
On Error Goto Handle_Error
Set aClass = New mycomponent.Myclass
' (call some methods on aClass)
Exit function
Handle_Error:
foo = Err.Description
finish perform
on this illustration, the class instance will also be dimensioned as comfortably myclass. The whole statement within the type <component-name>.<class-name> guards against title collisions
in the previous two examples, the category instance used to make the system name was a neighborhood variable of the method. This creates and destroys a brand new category instance for each call. An alternative method is to declare one single module-scoped category instance that's reused by all perform calls, as in the initialization code of the previous example.
The following example illustrates this procedure with the 2d system:
Dim aClass As mycomponent.Myclass
perform foo(x1 As Variant, x2 As Variant) As Variant
On Error Goto Handle_Error
If aClass Is Nothing Then
Set aClass = New mycomponent.Myclass
end If
' (name some approaches on aClass)
Exit operate
Handle_Error:
foo = Err.Description
end perform
How the MATLAB Runtime Is Shared amongst lessons
MATLAB Compiler creates a single MATLAB Runtime when
the first Microsoft COM type is instantiated in an software. This MATLAB Runtime is reused and shared among all subsequent classification occasions within the component, resulting in more efficient reminiscence usage and eliminating the MATLAB Runtime startup rate in each and every subsequent class instantiation.
All type instances share a single MATLAB workspace and share global variables within the MATLAB documents used to construct the aspect. This makes houses of a COM class behave as static properties as an alternative of illustration-intelligent properties.
Call the approaches of a class example
after getting created a class illustration, that you could call the class methods to access the compiled MATLAB functions. MATLAB Compiler applies a general mapping from the fashioned MATLAB function syntax to the system's argument record. See Reference Utility courses for a targeted description of
the mapping from MATLAB features to COM category system calls.
When a process has output arguments, the primary argument is perpetually nargout, which is of form long. This enter parameter passes the usual MATLAB nargout parameter to the
compiled operate and specifies what number of outputs are requested. Ways that do not have output arguments do not go a nargout argument. Following nargout are the output parameters listed in the equal order as they appear on the left aspect of the fashioned MATLAB operate. Next come the input parameters listed within the identical order as they appear on the right side of the original MATLAB operate. All enter and output arguments are typed as Variant, the default visible common information sort.
The Variant sort can preserve any of the fundamental VBA forms, arrays of any kind, and object references. See information Conversion principles for a unique description of how to transform Variant types of any common form to and from MATLAB knowledge types. Ordinarily, you can provide any visible basic form as an argument to a class procedure, aside from visual normal UDTs. You could additionally go Microsoft Excel variety objects straight as input and output arguments.
Whilst you cross a simple Variant type as an output parameter, the known as approach allocates the received data and frees the original contents of the Variant. On this case it's adequate to dimension each and every output argument as a single Variant. When an object type (like an Excel variety) is handed as an output parameter, the item reference is handed in each directions, and the item's price property receives the information.
The following examples illustrate the method of passing enter and output parameters from VBA to the MATLAB Compiler element class methods.
The primary illustration is a formulation perform that takes two inputs and returns one output. This function dispatches the call to a class procedure that corresponds to a MATLAB operate of the form operate y = foo(x1,x2).
Operate foo(x1 As Variant, x2 As Variant) As Variant
Dim aClass As Object
Dim y As Variant

On Error Goto Handle_Error
Set aClass = New mycomponent.Myclass
aClass = CreateObject("mycomponent.Myclass.1_0")
name aClass.Foo(1,y,x1,x2)
foo = y
Exit perform
Handle_Error:
foo = Err.Description
finish function
The second illustration rewrites the identical operate as a subroutine and uses Excel levels for enter and output.
Sub foo(Rout As variety, Rin1 As variety, Rin2 As variety)
Dim aClass As Object
On Error Goto Handle_Error
aClass = CreateObject("mycomponent.Myclass.1_0")
name aClass.Foo(1,Rout,Rin1,Rin2)
Exit Sub
Handle_Error:
MsgBox(Err.Description)
finish Sub
application with Variable Arguments
procedure varargin and varargout Arguments
When varargin and/or varargout are gift within the MATLAB function that you're using for the Excel element, these parameters are delivered to the argument list of the class method because the last input/output parameters within the record. You can cross more than one arguments as a varargin array via creating a Variant array, assigning every element of the array to the respective input argument.
The next instance creates a varargin array to call a system due to a MATLAB function of the form y = foo(varargin):
function foo(x1 As Variant, x2 As Variant, x3 As Variant, _
x4 As Variant, x5 As Variant) As Variant
Dim aClass As Object
Dim v As Variant
Dim y As Variant
Dim MCLUtil As Object
  
On Error GoTo Handle_Error
set aClass = CreateObject("mycomponent.Myclass.1_0")
Set MCLUtil = CreateObject("MWComUtil.MWUtil")
call MCLUtil.MWPack(v, x1, x2, x3, x4, x5)
name aClass.Foo(1, y, v)
foo = y
Exit perform
Handle_Error:
foo = Err.Description
finish operate
The MWUtil class integrated in the MWComUtil utility library presents the MWPack helper perform to create varargin parameters. See classification MWUtil for more small print.
The subsequent instance methods a varargout parameter into three separate Excel tiers. This operate makes use of the MWUnpack function within the utility library. The MATLAB function used is varargout = foo(x1,x2).
Sub foo(Rout1 As variety, Rout2 As range, Rout3 As range, _
Rin1 As variety, Rin2 As variety)
Dim aClass As Object
Dim aUtil As Object
Dim v As Variant
  
On Error Goto Handle_Error
aUtil = CreateObject("MWComUtil.MWUtil")
aClass = CreateObject("mycomponent.Myclass.1_0")
call aClass.Foo(three,v,Rin1,Rin2)
call aUtil.MWUnpack(v,zero,real,Rout1,Rout2,Rout3)
Exit Sub
Handle_Error:
MsgBox(Err.Description)
end Sub


Related Solutions

q1) using Matlab make a code that allows a user to enter a function like fractional...
q1) using Matlab make a code that allows a user to enter a function like fractional function and cubic liner function then the Matlab send a domain, range, continuity
Make a function in C that allows for the user to enter in 2 separate strings....
Make a function in C that allows for the user to enter in 2 separate strings. The first string that is entered is then made equal to the second string, but any duplicate characters (the same character appearing twice or more in a row) should only be copied once to the output string. Lastly the function displays how many duplicate characters were found.
Using PHP, Make a form that allows the user to enter the weight of the item...
Using PHP, Make a form that allows the user to enter the weight of the item being shipped. This will be used to calculate the shipping cost.Create a form that uses the method POST The form should capture a customer's package weight with the one field for the package weight in pounds. All fields should have the REQUIRED attribute. The form should have a submit button and a reset button. The form should look nice. All the labels should line...
Write out code for a nested if statement that allows a user to enter in a...
Write out code for a nested if statement that allows a user to enter in a product name, store the product into a variable called product name and checks to see if that product exists in your nested if statement. You must include 5 product names to search for. If it is then assign the price of the item to a variable called amount and then print the product name and the cost of the product to the console. If...
Write a MATLAB program to do the following: 1- Allows the user to enter unlimited number...
Write a MATLAB program to do the following: 1- Allows the user to enter unlimited number of data set. 2- Allows the user to exit the program at any time by entering zero. 3- Calculates and displays the following statistics for the entered data set: a- Count of positive, negative, and total numbers. b- Maximum and Minimum numbers. c- Sum and Average of positive numbers. d- Sum and Average of negative numbers. e- Overall Sum and overall average of all...
Write Java code that allows a user to repeatedly enter numbers. Each time the user enters...
Write Java code that allows a user to repeatedly enter numbers. Each time the user enters a number, the program should print out the average of the last 3 numbers (or all numbers if 3 or less have been entered). I would like a detailed explanation so that a beginner level Java programmer could understand.
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
C++ Write the C++ code for a void function that prompts the user to enter a...
C++ Write the C++ code for a void function that prompts the user to enter a name, and then stores the user's response in the string variable whose address is passed to the function. Name the function getName.
Using python, allows a user to enter the values of two, 3x3 matrices and then select...
Using python, allows a user to enter the values of two, 3x3 matrices and then select from options including, addition, subtraction, matrix multiplication, and element by element multiplication. You should use numpy.matmul()for matrix multiplication(e.g. np.matmul(a, b)).The program should computer the appropriate results and return the results, the transpose of the results, the mean of the rows for the results, and the mean of the columns for the results.When entering data you should check that each value is numeric for the...
DATA STRUCTURES USING C++ 2ND EDITION Write a program that allows the user to enter the...
DATA STRUCTURES USING C++ 2ND EDITION Write a program that allows the user to enter the last names of five candidates in a local election and the votes received by that candidate. The program should then output each candidates name, votes received by that candidate, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is as follow Johnson    5000 25.91 miller    4000   ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT