Category: Matlab
Category Archives: Matlab
Save a 3D image to TIFF
Hi everyone,
I made a bwdist transform of some image and I am struggling to export it to the .tiff format. Actually I want to create a 2D image stack representing a 3D volume. I read about imwrite which says it cannot save an image with so many layers, and then about tiff function, but not sure how to you use it.. The original image was created using ImageJ and was in the tiff format, now I need to export the MATLAB’s outcome back to tiff.
I’d appreciate your help.Hi everyone,
I made a bwdist transform of some image and I am struggling to export it to the .tiff format. Actually I want to create a 2D image stack representing a 3D volume. I read about imwrite which says it cannot save an image with so many layers, and then about tiff function, but not sure how to you use it.. The original image was created using ImageJ and was in the tiff format, now I need to export the MATLAB’s outcome back to tiff.
I’d appreciate your help. Hi everyone,
I made a bwdist transform of some image and I am struggling to export it to the .tiff format. Actually I want to create a 2D image stack representing a 3D volume. I read about imwrite which says it cannot save an image with so many layers, and then about tiff function, but not sure how to you use it.. The original image was created using ImageJ and was in the tiff format, now I need to export the MATLAB’s outcome back to tiff.
I’d appreciate your help. image export, save to tiff, image analysis, tiff MATLAB Answers — New Questions
“Empty sym” when solving a system of linear equations with different conditions
I have a system of linear equations with several conditions describing a kinematic analysis of an automatic gearbox. The system is the following:
where all values are positive.
Then the following conditions are applied
These conditions are permanently valid. Thereafter other conditions are going to be applied according to the engaged gear. For example in fifth gear, the further conditions are:
The aim is to obtain a symblic equation expression consisting of parameters , which defines the gear ratio between the output and input. The gear ratio in 5th gear is for instance
Mathematically the system has 12 unknonws and 11 equations, so it gives exactly the expression for the ratio between the output and input as a function of parameters .
The transmission has a total of 10 gears, so it would be pretty difficult to make all manually.
My idea was creating a code as follows:
syms Z1A Z2A Z3A Z4A Z1B Z2B Z3B Z4B positive
syms w1A w2A w3A w4A …
w1B w2B w3B w4B …
w1C w2C w3C w4C i
% System of equations
eqn1 = w1A*Z1A + w1B*Z1B == w1C*(Z1A+Z1B);
eqn2 = w2A*Z2A + w2B*Z2B == w2C*(Z2A+Z2B);
eqn3 = w3A*Z3A + w3B*Z3B == w3C*(Z3A+Z3B);
eqn4 = w4A*Z4A + w4B*Z4B == w4C*(Z4A+Z4B);
% Permanently valid conditions
cond1 = w2A == w1A;
cond2 = w2B == w3A;
cond3 = w1C == w4B;
cond4 = w3B == w4A;
% Fifth gear analysis example
w1B = 0;
cond_gear5_1 = w4C == w3C;
cond_gear5_2 = w2B == w4A;
ratio = i == w4C/w4A;
Sol = solve([eqn1 eqn2 eqn3 eqn4 …
cond1 cond2 cond3 cond4 …
cond_gear5_1 cond_gear5_2 ratio], i)
I was probably too optimistic about getting the desired expression from Matlab. The problem is that I don’t know how to make it work.
Each advice is appreciated.I have a system of linear equations with several conditions describing a kinematic analysis of an automatic gearbox. The system is the following:
where all values are positive.
Then the following conditions are applied
These conditions are permanently valid. Thereafter other conditions are going to be applied according to the engaged gear. For example in fifth gear, the further conditions are:
The aim is to obtain a symblic equation expression consisting of parameters , which defines the gear ratio between the output and input. The gear ratio in 5th gear is for instance
Mathematically the system has 12 unknonws and 11 equations, so it gives exactly the expression for the ratio between the output and input as a function of parameters .
The transmission has a total of 10 gears, so it would be pretty difficult to make all manually.
My idea was creating a code as follows:
syms Z1A Z2A Z3A Z4A Z1B Z2B Z3B Z4B positive
syms w1A w2A w3A w4A …
w1B w2B w3B w4B …
w1C w2C w3C w4C i
% System of equations
eqn1 = w1A*Z1A + w1B*Z1B == w1C*(Z1A+Z1B);
eqn2 = w2A*Z2A + w2B*Z2B == w2C*(Z2A+Z2B);
eqn3 = w3A*Z3A + w3B*Z3B == w3C*(Z3A+Z3B);
eqn4 = w4A*Z4A + w4B*Z4B == w4C*(Z4A+Z4B);
% Permanently valid conditions
cond1 = w2A == w1A;
cond2 = w2B == w3A;
cond3 = w1C == w4B;
cond4 = w3B == w4A;
% Fifth gear analysis example
w1B = 0;
cond_gear5_1 = w4C == w3C;
cond_gear5_2 = w2B == w4A;
ratio = i == w4C/w4A;
Sol = solve([eqn1 eqn2 eqn3 eqn4 …
cond1 cond2 cond3 cond4 …
cond_gear5_1 cond_gear5_2 ratio], i)
I was probably too optimistic about getting the desired expression from Matlab. The problem is that I don’t know how to make it work.
Each advice is appreciated. I have a system of linear equations with several conditions describing a kinematic analysis of an automatic gearbox. The system is the following:
where all values are positive.
Then the following conditions are applied
These conditions are permanently valid. Thereafter other conditions are going to be applied according to the engaged gear. For example in fifth gear, the further conditions are:
The aim is to obtain a symblic equation expression consisting of parameters , which defines the gear ratio between the output and input. The gear ratio in 5th gear is for instance
Mathematically the system has 12 unknonws and 11 equations, so it gives exactly the expression for the ratio between the output and input as a function of parameters .
The transmission has a total of 10 gears, so it would be pretty difficult to make all manually.
My idea was creating a code as follows:
syms Z1A Z2A Z3A Z4A Z1B Z2B Z3B Z4B positive
syms w1A w2A w3A w4A …
w1B w2B w3B w4B …
w1C w2C w3C w4C i
% System of equations
eqn1 = w1A*Z1A + w1B*Z1B == w1C*(Z1A+Z1B);
eqn2 = w2A*Z2A + w2B*Z2B == w2C*(Z2A+Z2B);
eqn3 = w3A*Z3A + w3B*Z3B == w3C*(Z3A+Z3B);
eqn4 = w4A*Z4A + w4B*Z4B == w4C*(Z4A+Z4B);
% Permanently valid conditions
cond1 = w2A == w1A;
cond2 = w2B == w3A;
cond3 = w1C == w4B;
cond4 = w3B == w4A;
% Fifth gear analysis example
w1B = 0;
cond_gear5_1 = w4C == w3C;
cond_gear5_2 = w2B == w4A;
ratio = i == w4C/w4A;
Sol = solve([eqn1 eqn2 eqn3 eqn4 …
cond1 cond2 cond3 cond4 …
cond_gear5_1 cond_gear5_2 ratio], i)
I was probably too optimistic about getting the desired expression from Matlab. The problem is that I don’t know how to make it work.
Each advice is appreciated. symbolic, solve, system of equations MATLAB Answers — New Questions
Passing additional minibatchable quantities to a trainnet() loss function
I am calling trainnet() with the syntax,
netTrained = trainnet(cds,net,lossFcn,options)
where lossFcn=f(Y,T) is a handle to a custom loss function. Here the variable Y is the network prediction based on input X and T is the training target. Both Y and T are S1xS2xC images. During training, the usual operation of trainnet() is to fetch minibatched pairs (X,T) pointed to by the CombinedDataStore cds and to give the pairs (Y(X),T) to the lossFcn.
I would now like to modify the training to have a loss function of the form lossFcn=f(Y,T,W) where W is an additional minibatchable data set of the same dimensions as Y and T containing constant weights. My question is if there is a way to combine 3 datastores instead of 2 datastores to make this happen. In other words, instead of cds reading in minibatched pairs (X,T), is it possible to have it read in minibatched triplets (X,T,W)? Moreover, will trainnet() know the role of each of member of the triplet, i.e., that X are the network inputs and that (T,W) are ‘other stuff’? Or how am I meant to communicate this?I am calling trainnet() with the syntax,
netTrained = trainnet(cds,net,lossFcn,options)
where lossFcn=f(Y,T) is a handle to a custom loss function. Here the variable Y is the network prediction based on input X and T is the training target. Both Y and T are S1xS2xC images. During training, the usual operation of trainnet() is to fetch minibatched pairs (X,T) pointed to by the CombinedDataStore cds and to give the pairs (Y(X),T) to the lossFcn.
I would now like to modify the training to have a loss function of the form lossFcn=f(Y,T,W) where W is an additional minibatchable data set of the same dimensions as Y and T containing constant weights. My question is if there is a way to combine 3 datastores instead of 2 datastores to make this happen. In other words, instead of cds reading in minibatched pairs (X,T), is it possible to have it read in minibatched triplets (X,T,W)? Moreover, will trainnet() know the role of each of member of the triplet, i.e., that X are the network inputs and that (T,W) are ‘other stuff’? Or how am I meant to communicate this? I am calling trainnet() with the syntax,
netTrained = trainnet(cds,net,lossFcn,options)
where lossFcn=f(Y,T) is a handle to a custom loss function. Here the variable Y is the network prediction based on input X and T is the training target. Both Y and T are S1xS2xC images. During training, the usual operation of trainnet() is to fetch minibatched pairs (X,T) pointed to by the CombinedDataStore cds and to give the pairs (Y(X),T) to the lossFcn.
I would now like to modify the training to have a loss function of the form lossFcn=f(Y,T,W) where W is an additional minibatchable data set of the same dimensions as Y and T containing constant weights. My question is if there is a way to combine 3 datastores instead of 2 datastores to make this happen. In other words, instead of cds reading in minibatched pairs (X,T), is it possible to have it read in minibatched triplets (X,T,W)? Moreover, will trainnet() know the role of each of member of the triplet, i.e., that X are the network inputs and that (T,W) are ‘other stuff’? Or how am I meant to communicate this? trainnet, datastore, minibatch, deep learning, ai MATLAB Answers — New Questions
Convert 0×1 empty double column vector to zero
I am running a code and some of the parameters are 0×1 empty double column vector. Is there any way to convert these to zero?
I mean isntead of daying empty double, assign zero.I am running a code and some of the parameters are 0×1 empty double column vector. Is there any way to convert these to zero?
I mean isntead of daying empty double, assign zero. I am running a code and some of the parameters are 0×1 empty double column vector. Is there any way to convert these to zero?
I mean isntead of daying empty double, assign zero. double, vector MATLAB Answers — New Questions
Using ’tiledlayout’, is it possible to incorporate a zoomed-in section of the main plot within the main plot itself for each tile?
Hi, I created 3 main plots (black square) using ’tiledlayout’, and i would like to include a zoomed-in area of each main plots (red square) within the same tile. Is this possible to do? The figure below shows, what i would like.Hi, I created 3 main plots (black square) using ’tiledlayout’, and i would like to include a zoomed-in area of each main plots (red square) within the same tile. Is this possible to do? The figure below shows, what i would like. Hi, I created 3 main plots (black square) using ’tiledlayout’, and i would like to include a zoomed-in area of each main plots (red square) within the same tile. Is this possible to do? The figure below shows, what i would like. matlab, tiledlayout MATLAB Answers — New Questions
Can I update my Matlab behavior
Sorry for the poor title, not sure how to explain it.
I have two questions:
1) When we write three dots to split a command line, can we change what happens?
examplepath = ‘thisisapath’; % This is a random string
examplepath = [‘thisisa…’ …
‘path’]; % this is the same string if I write three dots "…" somewhere
% This is a bad behavior because it breaks the string
%% What I want Matlab to do when I write three dots:
examplepath = [‘thisisa’, …
‘path’];
This is what I want to do when I write three dots and press enter, I want to split whatever I wrote so it fits on 2 lines and I don’t have to use the horizontal slider bar because my sentence is too long. Is it be possible to update such behavior?
2) Indentation changed a few versions ago, I now use 2023a.
If I have a loop for example, when I paste code to it, I want it to be indented where it should be by default, not at the begining of the line. Example:
for i = 1:10
% something I wrote here here
% someting I pasted
end
%% It should be:
for i = 1:10
% something I wrote here here
% someting I pasted
end
It would be great to save these selection + ctrl+i, clicking at a random place inside a loop before was giving you an indented space, I want the same behavior.
Thanks!Sorry for the poor title, not sure how to explain it.
I have two questions:
1) When we write three dots to split a command line, can we change what happens?
examplepath = ‘thisisapath’; % This is a random string
examplepath = [‘thisisa…’ …
‘path’]; % this is the same string if I write three dots "…" somewhere
% This is a bad behavior because it breaks the string
%% What I want Matlab to do when I write three dots:
examplepath = [‘thisisa’, …
‘path’];
This is what I want to do when I write three dots and press enter, I want to split whatever I wrote so it fits on 2 lines and I don’t have to use the horizontal slider bar because my sentence is too long. Is it be possible to update such behavior?
2) Indentation changed a few versions ago, I now use 2023a.
If I have a loop for example, when I paste code to it, I want it to be indented where it should be by default, not at the begining of the line. Example:
for i = 1:10
% something I wrote here here
% someting I pasted
end
%% It should be:
for i = 1:10
% something I wrote here here
% someting I pasted
end
It would be great to save these selection + ctrl+i, clicking at a random place inside a loop before was giving you an indented space, I want the same behavior.
Thanks! Sorry for the poor title, not sure how to explain it.
I have two questions:
1) When we write three dots to split a command line, can we change what happens?
examplepath = ‘thisisapath’; % This is a random string
examplepath = [‘thisisa…’ …
‘path’]; % this is the same string if I write three dots "…" somewhere
% This is a bad behavior because it breaks the string
%% What I want Matlab to do when I write three dots:
examplepath = [‘thisisa’, …
‘path’];
This is what I want to do when I write three dots and press enter, I want to split whatever I wrote so it fits on 2 lines and I don’t have to use the horizontal slider bar because my sentence is too long. Is it be possible to update such behavior?
2) Indentation changed a few versions ago, I now use 2023a.
If I have a loop for example, when I paste code to it, I want it to be indented where it should be by default, not at the begining of the line. Example:
for i = 1:10
% something I wrote here here
% someting I pasted
end
%% It should be:
for i = 1:10
% something I wrote here here
% someting I pasted
end
It would be great to save these selection + ctrl+i, clicking at a random place inside a loop before was giving you an indented space, I want the same behavior.
Thanks! behavior MATLAB Answers — New Questions
Replace certain columns in a structure array
Hi. I have a structure array, Data, of size (1 x120). The 5th column of the field Data.Temp contains zeroes. I want to replace these zeroes with a number 20 from Data(30).Temp to Data(60).Temp. Also, I want to replace these zeroes from Data(61).Temp to Data(80).Temp with a number 24. I am unable to perform this operation. I kindly request some help from the community.Hi. I have a structure array, Data, of size (1 x120). The 5th column of the field Data.Temp contains zeroes. I want to replace these zeroes with a number 20 from Data(30).Temp to Data(60).Temp. Also, I want to replace these zeroes from Data(61).Temp to Data(80).Temp with a number 24. I am unable to perform this operation. I kindly request some help from the community. Hi. I have a structure array, Data, of size (1 x120). The 5th column of the field Data.Temp contains zeroes. I want to replace these zeroes with a number 20 from Data(30).Temp to Data(60).Temp. Also, I want to replace these zeroes from Data(61).Temp to Data(80).Temp with a number 24. I am unable to perform this operation. I kindly request some help from the community. structure array, array, cell MATLAB Answers — New Questions
Get coordinates of points from an image
Hello,
I would like to know how to obtain the coordinates of p number of random points from an image:
how to call an image ( do i have to specify the path of the folder and how?)
How to obtain the data of x axix and y axis corresponding to it
Shall i use the function getimage?
Thank youHello,
I would like to know how to obtain the coordinates of p number of random points from an image:
how to call an image ( do i have to specify the path of the folder and how?)
How to obtain the data of x axix and y axis corresponding to it
Shall i use the function getimage?
Thank you Hello,
I would like to know how to obtain the coordinates of p number of random points from an image:
how to call an image ( do i have to specify the path of the folder and how?)
How to obtain the data of x axix and y axis corresponding to it
Shall i use the function getimage?
Thank you getimage, coordinates, image, data MATLAB Answers — New Questions
how to remove areas of an image containing a single color?
I have a video that I saved each frame from. The entire video has static text in big white font and it doesnt move so each frame looks very similar. Each frame also has a black background like I want to remove. Is there a way for me to remove any pixle that is (0,0,0) or (1, 1, 1) RGB? Thanks!
heres an example image that I want to crop. I want to crop all of the black and all of the white.I have a video that I saved each frame from. The entire video has static text in big white font and it doesnt move so each frame looks very similar. Each frame also has a black background like I want to remove. Is there a way for me to remove any pixle that is (0,0,0) or (1, 1, 1) RGB? Thanks!
heres an example image that I want to crop. I want to crop all of the black and all of the white. I have a video that I saved each frame from. The entire video has static text in big white font and it doesnt move so each frame looks very similar. Each frame also has a black background like I want to remove. Is there a way for me to remove any pixle that is (0,0,0) or (1, 1, 1) RGB? Thanks!
heres an example image that I want to crop. I want to crop all of the black and all of the white. image processing MATLAB Answers — New Questions
Programmatically Disable a Toolbox
I have an external toolbox (created by me) and I want to disable it (not uninstall it), do some stuff, and then re-enable it.
I have looked through the available methods in matlab.addons.toolbox, but I only see options for installing and uninstalling.
Looking at other ideas, removing the paths would be a way to disable the toolbox, but how do I know (programatically) what paths to remove? Looking in the Add-Ons explorer I can see the paths associated with the toolbox and I have an option to diasble it, but I can’t get either of those through the matlab.addons.toolbox API.
I think I either need a way to get the paths for the toolbox, or I need a method that allows me to disable it.
Am I missing something that exists today to do this?I have an external toolbox (created by me) and I want to disable it (not uninstall it), do some stuff, and then re-enable it.
I have looked through the available methods in matlab.addons.toolbox, but I only see options for installing and uninstalling.
Looking at other ideas, removing the paths would be a way to disable the toolbox, but how do I know (programatically) what paths to remove? Looking in the Add-Ons explorer I can see the paths associated with the toolbox and I have an option to diasble it, but I can’t get either of those through the matlab.addons.toolbox API.
I think I either need a way to get the paths for the toolbox, or I need a method that allows me to disable it.
Am I missing something that exists today to do this? I have an external toolbox (created by me) and I want to disable it (not uninstall it), do some stuff, and then re-enable it.
I have looked through the available methods in matlab.addons.toolbox, but I only see options for installing and uninstalling.
Looking at other ideas, removing the paths would be a way to disable the toolbox, but how do I know (programatically) what paths to remove? Looking in the Add-Ons explorer I can see the paths associated with the toolbox and I have an option to diasble it, but I can’t get either of those through the matlab.addons.toolbox API.
I think I either need a way to get the paths for the toolbox, or I need a method that allows me to disable it.
Am I missing something that exists today to do this? toolbox, disable, toolbox paths MATLAB Answers — New Questions
Create a simulink model fro, python
Hello,
I would like to create an algorithm using evolutionnary strategies in order to identify physical systems represented by block diagrams. To do so, I will need to design an algorithm where a population of systems is modified (not only the parameters but also the structure) and tested at each iteration. I need to simulate the resulting population and in order to do that I need to be able to change one block of the model in simulink, which would be a sub system with different transfer functions. I don’t know simulink very well so is there a way to crate a custom block, to simulate the model from python and to change one part of the model at each run?
Thank you in advance,Hello,
I would like to create an algorithm using evolutionnary strategies in order to identify physical systems represented by block diagrams. To do so, I will need to design an algorithm where a population of systems is modified (not only the parameters but also the structure) and tested at each iteration. I need to simulate the resulting population and in order to do that I need to be able to change one block of the model in simulink, which would be a sub system with different transfer functions. I don’t know simulink very well so is there a way to crate a custom block, to simulate the model from python and to change one part of the model at each run?
Thank you in advance, Hello,
I would like to create an algorithm using evolutionnary strategies in order to identify physical systems represented by block diagrams. To do so, I will need to design an algorithm where a population of systems is modified (not only the parameters but also the structure) and tested at each iteration. I need to simulate the resulting population and in order to do that I need to be able to change one block of the model in simulink, which would be a sub system with different transfer functions. I don’t know simulink very well so is there a way to crate a custom block, to simulate the model from python and to change one part of the model at each run?
Thank you in advance, simulink, python, optimization MATLAB Answers — New Questions
Nonlinear optimization with branching solution space
I would like to solve a nonlinear optimization problem with nonlinear constraints, in which the solution space branches, such that the relevant optimization parameters and their constraints depend upon the branch. In total the problem has 11 optimization parameters however not all parameters are possible together. The primary parameter is an integer ‘x’ = 1-10 (although it could be treated as a continuous variable). The error function f(x) depends also upon other parameters as follows. If x < 10 the error function is f(x, c, d = 0) where ‘c’ is 5 other continuous parameters with constraints, elseif x = 10 the error function is f(x, c = 0, d) where ‘d’ is 5 different continuous parameters with constraints.
It seems simplest to first solve for x assuming c = 0 and d = 0, then solve for ‘c and ‘d’ depending upon the branch, i.e., depending upon whether x < 10 or x = 10, however, those attempts have failed, because if ‘c’ or ‘d’ are nonzero, the data are affected and the solutions for x are incorrect.
Two questions please;
1) Is this problem even well-posed as stated?
2) Does optimization or global optimization have a tool that can solve this?I would like to solve a nonlinear optimization problem with nonlinear constraints, in which the solution space branches, such that the relevant optimization parameters and their constraints depend upon the branch. In total the problem has 11 optimization parameters however not all parameters are possible together. The primary parameter is an integer ‘x’ = 1-10 (although it could be treated as a continuous variable). The error function f(x) depends also upon other parameters as follows. If x < 10 the error function is f(x, c, d = 0) where ‘c’ is 5 other continuous parameters with constraints, elseif x = 10 the error function is f(x, c = 0, d) where ‘d’ is 5 different continuous parameters with constraints.
It seems simplest to first solve for x assuming c = 0 and d = 0, then solve for ‘c and ‘d’ depending upon the branch, i.e., depending upon whether x < 10 or x = 10, however, those attempts have failed, because if ‘c’ or ‘d’ are nonzero, the data are affected and the solutions for x are incorrect.
Two questions please;
1) Is this problem even well-posed as stated?
2) Does optimization or global optimization have a tool that can solve this? I would like to solve a nonlinear optimization problem with nonlinear constraints, in which the solution space branches, such that the relevant optimization parameters and their constraints depend upon the branch. In total the problem has 11 optimization parameters however not all parameters are possible together. The primary parameter is an integer ‘x’ = 1-10 (although it could be treated as a continuous variable). The error function f(x) depends also upon other parameters as follows. If x < 10 the error function is f(x, c, d = 0) where ‘c’ is 5 other continuous parameters with constraints, elseif x = 10 the error function is f(x, c = 0, d) where ‘d’ is 5 different continuous parameters with constraints.
It seems simplest to first solve for x assuming c = 0 and d = 0, then solve for ‘c and ‘d’ depending upon the branch, i.e., depending upon whether x < 10 or x = 10, however, those attempts have failed, because if ‘c’ or ‘d’ are nonzero, the data are affected and the solutions for x are incorrect.
Two questions please;
1) Is this problem even well-posed as stated?
2) Does optimization or global optimization have a tool that can solve this? optimization MATLAB Answers — New Questions
str2num is returning and empty matrix: []
Problem:
I’m trying to convert a string containing a number into a double, but the output of str2num keeps giving me an empty matrix [].
Context:
I’ve imported data from an excel sheet with importdata(). That data comes in as a cell array. To extract data from a specific cell, I use cell2mat(). This yeilds numbers in the class: Char. (Example: ‘5’). I use convertCharsToString(‘5’) to convert that character into a string. What I’m left with is ans = "5".
Now, I want to convert this "5" into a double. So, I used str2num(ans), and I get [] as the output (instead of 5 of class double).
I even tried this debugg:
a = "5";
strcmp(a,month)
and got a logical = 0…
Any ideas why this isn’t woking?Problem:
I’m trying to convert a string containing a number into a double, but the output of str2num keeps giving me an empty matrix [].
Context:
I’ve imported data from an excel sheet with importdata(). That data comes in as a cell array. To extract data from a specific cell, I use cell2mat(). This yeilds numbers in the class: Char. (Example: ‘5’). I use convertCharsToString(‘5’) to convert that character into a string. What I’m left with is ans = "5".
Now, I want to convert this "5" into a double. So, I used str2num(ans), and I get [] as the output (instead of 5 of class double).
I even tried this debugg:
a = "5";
strcmp(a,month)
and got a logical = 0…
Any ideas why this isn’t woking? Problem:
I’m trying to convert a string containing a number into a double, but the output of str2num keeps giving me an empty matrix [].
Context:
I’ve imported data from an excel sheet with importdata(). That data comes in as a cell array. To extract data from a specific cell, I use cell2mat(). This yeilds numbers in the class: Char. (Example: ‘5’). I use convertCharsToString(‘5’) to convert that character into a string. What I’m left with is ans = "5".
Now, I want to convert this "5" into a double. So, I used str2num(ans), and I get [] as the output (instead of 5 of class double).
I even tried this debugg:
a = "5";
strcmp(a,month)
and got a logical = 0…
Any ideas why this isn’t woking? str2num empty matrix string not working MATLAB Answers — New Questions
Images are rotated counter clockwise without any reason,
Hi,
So, I’m working on a code where I have a folder with 33 images and they are of different orientation (mix of landscape and portrait sizes). I have the script that reads the images from the folder and overlay gaze data on top of these images. The script is running fine except a small bug that im facing is that for final plot of 33 images, some images that are actually portrait size (elongated top to bottom) are plotted with counter clock-wise rotation to show it as a landscape.
The two images below are for reference. where Img x025 is correct plotted with right data but Img x033 is incorrect and its rotated and therefore the gaze data is correct but due to rotation, its not overlaid correctly.
I want the x033 image to look like this below and there are about 12-14 images that are displayed or showed in this way with wrong orientation:
The code is as follows, which is part of a larger script:
imageDir = ‘C:Usersmqs6680Downloadssaliency-masterimages1’;
% Load the data
filename = ‘DD2.tsv’;
opts = detectImportOptions(filename, ‘FileType’, ‘text’);
data = readtable(filename, opts);
% Get unique participants
participants = unique(data.(‘ParticipantName’));
% Initialize a structure for participants
participantData = struct();
% Get a list of all JPG files in the folder
imageFiles = dir(fullfile(imageDir, ‘*.jpg’));
% Read resolutions and store in a map for quick lookup
resolutions = containers.Map(‘KeyType’, ‘char’, ‘ValueType’, ‘any’);
for i = 1:length(imageFiles)
imagePath = fullfile(imageDir, imageFiles(i).name);
img = imread(imagePath);
resolution = [size(img, 1), size(img, 2)]; % [height, width]
[~, imageID, ~] = fileparts(imageFiles(i).name);
resolutions(imageID) = resolution;
end
% Now you can access each participant’s data and each image’s data using:
% participantData.participantName_var.imageName_var
%% Individual Fixation map
% Assuming participantData is already filled from previous code
% Get all participant names from the structure
participantNames = fieldnames(participantData);
% Prompt user to enter a participant name or choose from a list
disp(‘Available participants:’);
disp(participantNames);
selectedParticipant = input(‘Enter the name of the participant to plot (case-sensitive): ‘, ‘s’);
% Check if the entered participant name is valid
if isfield(participantData, selectedParticipant)
% Get all images for the selected participant
imageNames = fieldnames(participantData.(selectedParticipant));
for j = 1:length(imageNames)
imageName = imageNames{j};
imageData = participantData.(selectedParticipant).(imageName);
% Ensure data exists for plotting
if ~isempty(imageData)
actualFixationX = imageData.ActualFixationX;
actualFixationY = imageData.ActualFixationY;
% Read the image from the file
imagePath = fullfile(‘C:Usersmqs6680Downloadssaliency-masterimages’, strcat(imageName, ‘.jpg’)); % Assumes image extension is jpg
img = imread(imagePath);
% Check if the image needs to be rotated (portrait orientation)
if size(img, 1) > size(img, 2)
img = imrotate(img, -90); % Rotate the image clockwise by 90 degrees
% Correctly swap and calculate new fixation points
tempX = actualFixationX; % Temporary variable for swapping
actualFixationX = actualFixationY; % New X is the old Y
actualFixationY = size(img, 1) – tempX + 1; % New Y is adjusted based on the new image height
end
% Create a scatter plot on top of the image
figure; % Create a new figure for each image
imshow(img, ‘InitialMagnification’, ‘fit’); % Display the image and fit it to the window
hold on; % Hold on to overlay scatter plot on the image
scatter(actualFixationX, actualFixationY, ‘filled’, ‘r’); % Red points
hold off; % Release the hold to allow further plots to be displayed separately
title(sprintf(‘Fixation Points on Image for Participant: %s, Image: %s’, selectedParticipant, imageName));
xlabel(‘Actual Fixation X (pixels)’);
ylabel(‘Actual Fixation Y (pixels)’);
% Explicitly set the axis limits to match the image dimensions
axis on; % Turn on axis lines, optional
xlim([0 size(img, 2)]); % Set x-axis limits based on image width
ylim([0 size(img, 1)]); % Set y-axis limits based on image height
end
end
else
fprintf(‘No data available for participant: %sn’, selectedParticipant);
end
Also, I have tried following different debugging methods:
Method 1:
% Check if the image needs to be rotated (portrait orientation)
if size(img, 1) > size(img, 2)
img = imrotate(img, -90); % Rotate the image clockwise by 90 degrees
% Swap X and Y fixation points for the rotated image
newFixationX = size(img, 1) – actualFixationY + 1; % Recalibrate to the new dimensions
newFixationY = actualFixationX;
actualFixationX = newFixationX;
actualFixationY = newFixationY;
end
Method 2:
% Check if the image needs to be rotated (portrait orientation)
if size(img, 1) > size(img, 2)
img = imrotate(img, -90); % Rotate the image clockwise by 90 degrees
% Swap X and Y fixation points for the rotated image
[actualFixationX, actualFixationY] = deal(actualFixationY, size(img, 2) – actualFixationX + 1);
end
I have cut portion of the code where it was handling the gaze data related stuff. Anyhelp will be appreciated. Thank you so much.Hi,
So, I’m working on a code where I have a folder with 33 images and they are of different orientation (mix of landscape and portrait sizes). I have the script that reads the images from the folder and overlay gaze data on top of these images. The script is running fine except a small bug that im facing is that for final plot of 33 images, some images that are actually portrait size (elongated top to bottom) are plotted with counter clock-wise rotation to show it as a landscape.
The two images below are for reference. where Img x025 is correct plotted with right data but Img x033 is incorrect and its rotated and therefore the gaze data is correct but due to rotation, its not overlaid correctly.
I want the x033 image to look like this below and there are about 12-14 images that are displayed or showed in this way with wrong orientation:
The code is as follows, which is part of a larger script:
imageDir = ‘C:Usersmqs6680Downloadssaliency-masterimages1’;
% Load the data
filename = ‘DD2.tsv’;
opts = detectImportOptions(filename, ‘FileType’, ‘text’);
data = readtable(filename, opts);
% Get unique participants
participants = unique(data.(‘ParticipantName’));
% Initialize a structure for participants
participantData = struct();
% Get a list of all JPG files in the folder
imageFiles = dir(fullfile(imageDir, ‘*.jpg’));
% Read resolutions and store in a map for quick lookup
resolutions = containers.Map(‘KeyType’, ‘char’, ‘ValueType’, ‘any’);
for i = 1:length(imageFiles)
imagePath = fullfile(imageDir, imageFiles(i).name);
img = imread(imagePath);
resolution = [size(img, 1), size(img, 2)]; % [height, width]
[~, imageID, ~] = fileparts(imageFiles(i).name);
resolutions(imageID) = resolution;
end
% Now you can access each participant’s data and each image’s data using:
% participantData.participantName_var.imageName_var
%% Individual Fixation map
% Assuming participantData is already filled from previous code
% Get all participant names from the structure
participantNames = fieldnames(participantData);
% Prompt user to enter a participant name or choose from a list
disp(‘Available participants:’);
disp(participantNames);
selectedParticipant = input(‘Enter the name of the participant to plot (case-sensitive): ‘, ‘s’);
% Check if the entered participant name is valid
if isfield(participantData, selectedParticipant)
% Get all images for the selected participant
imageNames = fieldnames(participantData.(selectedParticipant));
for j = 1:length(imageNames)
imageName = imageNames{j};
imageData = participantData.(selectedParticipant).(imageName);
% Ensure data exists for plotting
if ~isempty(imageData)
actualFixationX = imageData.ActualFixationX;
actualFixationY = imageData.ActualFixationY;
% Read the image from the file
imagePath = fullfile(‘C:Usersmqs6680Downloadssaliency-masterimages’, strcat(imageName, ‘.jpg’)); % Assumes image extension is jpg
img = imread(imagePath);
% Check if the image needs to be rotated (portrait orientation)
if size(img, 1) > size(img, 2)
img = imrotate(img, -90); % Rotate the image clockwise by 90 degrees
% Correctly swap and calculate new fixation points
tempX = actualFixationX; % Temporary variable for swapping
actualFixationX = actualFixationY; % New X is the old Y
actualFixationY = size(img, 1) – tempX + 1; % New Y is adjusted based on the new image height
end
% Create a scatter plot on top of the image
figure; % Create a new figure for each image
imshow(img, ‘InitialMagnification’, ‘fit’); % Display the image and fit it to the window
hold on; % Hold on to overlay scatter plot on the image
scatter(actualFixationX, actualFixationY, ‘filled’, ‘r’); % Red points
hold off; % Release the hold to allow further plots to be displayed separately
title(sprintf(‘Fixation Points on Image for Participant: %s, Image: %s’, selectedParticipant, imageName));
xlabel(‘Actual Fixation X (pixels)’);
ylabel(‘Actual Fixation Y (pixels)’);
% Explicitly set the axis limits to match the image dimensions
axis on; % Turn on axis lines, optional
xlim([0 size(img, 2)]); % Set x-axis limits based on image width
ylim([0 size(img, 1)]); % Set y-axis limits based on image height
end
end
else
fprintf(‘No data available for participant: %sn’, selectedParticipant);
end
Also, I have tried following different debugging methods:
Method 1:
% Check if the image needs to be rotated (portrait orientation)
if size(img, 1) > size(img, 2)
img = imrotate(img, -90); % Rotate the image clockwise by 90 degrees
% Swap X and Y fixation points for the rotated image
newFixationX = size(img, 1) – actualFixationY + 1; % Recalibrate to the new dimensions
newFixationY = actualFixationX;
actualFixationX = newFixationX;
actualFixationY = newFixationY;
end
Method 2:
% Check if the image needs to be rotated (portrait orientation)
if size(img, 1) > size(img, 2)
img = imrotate(img, -90); % Rotate the image clockwise by 90 degrees
% Swap X and Y fixation points for the rotated image
[actualFixationX, actualFixationY] = deal(actualFixationY, size(img, 2) – actualFixationX + 1);
end
I have cut portion of the code where it was handling the gaze data related stuff. Anyhelp will be appreciated. Thank you so much. Hi,
So, I’m working on a code where I have a folder with 33 images and they are of different orientation (mix of landscape and portrait sizes). I have the script that reads the images from the folder and overlay gaze data on top of these images. The script is running fine except a small bug that im facing is that for final plot of 33 images, some images that are actually portrait size (elongated top to bottom) are plotted with counter clock-wise rotation to show it as a landscape.
The two images below are for reference. where Img x025 is correct plotted with right data but Img x033 is incorrect and its rotated and therefore the gaze data is correct but due to rotation, its not overlaid correctly.
I want the x033 image to look like this below and there are about 12-14 images that are displayed or showed in this way with wrong orientation:
The code is as follows, which is part of a larger script:
imageDir = ‘C:Usersmqs6680Downloadssaliency-masterimages1’;
% Load the data
filename = ‘DD2.tsv’;
opts = detectImportOptions(filename, ‘FileType’, ‘text’);
data = readtable(filename, opts);
% Get unique participants
participants = unique(data.(‘ParticipantName’));
% Initialize a structure for participants
participantData = struct();
% Get a list of all JPG files in the folder
imageFiles = dir(fullfile(imageDir, ‘*.jpg’));
% Read resolutions and store in a map for quick lookup
resolutions = containers.Map(‘KeyType’, ‘char’, ‘ValueType’, ‘any’);
for i = 1:length(imageFiles)
imagePath = fullfile(imageDir, imageFiles(i).name);
img = imread(imagePath);
resolution = [size(img, 1), size(img, 2)]; % [height, width]
[~, imageID, ~] = fileparts(imageFiles(i).name);
resolutions(imageID) = resolution;
end
% Now you can access each participant’s data and each image’s data using:
% participantData.participantName_var.imageName_var
%% Individual Fixation map
% Assuming participantData is already filled from previous code
% Get all participant names from the structure
participantNames = fieldnames(participantData);
% Prompt user to enter a participant name or choose from a list
disp(‘Available participants:’);
disp(participantNames);
selectedParticipant = input(‘Enter the name of the participant to plot (case-sensitive): ‘, ‘s’);
% Check if the entered participant name is valid
if isfield(participantData, selectedParticipant)
% Get all images for the selected participant
imageNames = fieldnames(participantData.(selectedParticipant));
for j = 1:length(imageNames)
imageName = imageNames{j};
imageData = participantData.(selectedParticipant).(imageName);
% Ensure data exists for plotting
if ~isempty(imageData)
actualFixationX = imageData.ActualFixationX;
actualFixationY = imageData.ActualFixationY;
% Read the image from the file
imagePath = fullfile(‘C:Usersmqs6680Downloadssaliency-masterimages’, strcat(imageName, ‘.jpg’)); % Assumes image extension is jpg
img = imread(imagePath);
% Check if the image needs to be rotated (portrait orientation)
if size(img, 1) > size(img, 2)
img = imrotate(img, -90); % Rotate the image clockwise by 90 degrees
% Correctly swap and calculate new fixation points
tempX = actualFixationX; % Temporary variable for swapping
actualFixationX = actualFixationY; % New X is the old Y
actualFixationY = size(img, 1) – tempX + 1; % New Y is adjusted based on the new image height
end
% Create a scatter plot on top of the image
figure; % Create a new figure for each image
imshow(img, ‘InitialMagnification’, ‘fit’); % Display the image and fit it to the window
hold on; % Hold on to overlay scatter plot on the image
scatter(actualFixationX, actualFixationY, ‘filled’, ‘r’); % Red points
hold off; % Release the hold to allow further plots to be displayed separately
title(sprintf(‘Fixation Points on Image for Participant: %s, Image: %s’, selectedParticipant, imageName));
xlabel(‘Actual Fixation X (pixels)’);
ylabel(‘Actual Fixation Y (pixels)’);
% Explicitly set the axis limits to match the image dimensions
axis on; % Turn on axis lines, optional
xlim([0 size(img, 2)]); % Set x-axis limits based on image width
ylim([0 size(img, 1)]); % Set y-axis limits based on image height
end
end
else
fprintf(‘No data available for participant: %sn’, selectedParticipant);
end
Also, I have tried following different debugging methods:
Method 1:
% Check if the image needs to be rotated (portrait orientation)
if size(img, 1) > size(img, 2)
img = imrotate(img, -90); % Rotate the image clockwise by 90 degrees
% Swap X and Y fixation points for the rotated image
newFixationX = size(img, 1) – actualFixationY + 1; % Recalibrate to the new dimensions
newFixationY = actualFixationX;
actualFixationX = newFixationX;
actualFixationY = newFixationY;
end
Method 2:
% Check if the image needs to be rotated (portrait orientation)
if size(img, 1) > size(img, 2)
img = imrotate(img, -90); % Rotate the image clockwise by 90 degrees
% Swap X and Y fixation points for the rotated image
[actualFixationX, actualFixationY] = deal(actualFixationY, size(img, 2) – actualFixationX + 1);
end
I have cut portion of the code where it was handling the gaze data related stuff. Anyhelp will be appreciated. Thank you so much. data import, plotting, image analysis MATLAB Answers — New Questions
graph multiple excel or csv files
I have 4 excel files, which I would like to join using matlab into a single file like example 5 (but not convert it to excel). But using the time table command in which the date and time are combined, the purpose is to be able to graph various amounts of data quickly without graphing each file.
The purpose is when you have to graph excel or csv files to be able to generate them quickly
For example:
I really appreciate the help.
My code actual:
clear;
clc;
%% Load and plot data example 01
filename = ‘example1’;
T = readtable(filename);
x1 = T{:,1} + days(T{:,2}); % Combining date and time
y1 = T{:,3}; % Pressure data
figure
plot(x1, y1, ‘r-‘, ‘LineWidth’, 1)
hold on
%% Load and plot data example 02
filename = ‘example2’;
T = readtable(filename);
x2 = T{:,1} + days(T{:,2}); % Combining date and time
y2= T{:,3}; % Pressure data
plot(x2, y2, ‘b-‘, ‘LineWidth’, 1)
hold on
%% Load and plot data example 03
filename = ‘example3’;
T = readtable(filename);
x3 = T{:,1} + days(T{:,2}); % Combining date and time
y3= T{:,3}; % Pressure data
plot(x3, y3, ‘g-‘, ‘LineWidth’, 1)
hold on
%% Load and plot data example 04
filename = ‘example4’;
T = readtable(filename);
x4 = T{:,1} + days(T{:,2}); % Combining date and time
y4= T{:,3}; % Pressure data
plot(x4, y4, ‘k-‘, ‘LineWidth’, 1)
hold on
grid on
axis tightI have 4 excel files, which I would like to join using matlab into a single file like example 5 (but not convert it to excel). But using the time table command in which the date and time are combined, the purpose is to be able to graph various amounts of data quickly without graphing each file.
The purpose is when you have to graph excel or csv files to be able to generate them quickly
For example:
I really appreciate the help.
My code actual:
clear;
clc;
%% Load and plot data example 01
filename = ‘example1’;
T = readtable(filename);
x1 = T{:,1} + days(T{:,2}); % Combining date and time
y1 = T{:,3}; % Pressure data
figure
plot(x1, y1, ‘r-‘, ‘LineWidth’, 1)
hold on
%% Load and plot data example 02
filename = ‘example2’;
T = readtable(filename);
x2 = T{:,1} + days(T{:,2}); % Combining date and time
y2= T{:,3}; % Pressure data
plot(x2, y2, ‘b-‘, ‘LineWidth’, 1)
hold on
%% Load and plot data example 03
filename = ‘example3’;
T = readtable(filename);
x3 = T{:,1} + days(T{:,2}); % Combining date and time
y3= T{:,3}; % Pressure data
plot(x3, y3, ‘g-‘, ‘LineWidth’, 1)
hold on
%% Load and plot data example 04
filename = ‘example4’;
T = readtable(filename);
x4 = T{:,1} + days(T{:,2}); % Combining date and time
y4= T{:,3}; % Pressure data
plot(x4, y4, ‘k-‘, ‘LineWidth’, 1)
hold on
grid on
axis tight I have 4 excel files, which I would like to join using matlab into a single file like example 5 (but not convert it to excel). But using the time table command in which the date and time are combined, the purpose is to be able to graph various amounts of data quickly without graphing each file.
The purpose is when you have to graph excel or csv files to be able to generate them quickly
For example:
I really appreciate the help.
My code actual:
clear;
clc;
%% Load and plot data example 01
filename = ‘example1’;
T = readtable(filename);
x1 = T{:,1} + days(T{:,2}); % Combining date and time
y1 = T{:,3}; % Pressure data
figure
plot(x1, y1, ‘r-‘, ‘LineWidth’, 1)
hold on
%% Load and plot data example 02
filename = ‘example2’;
T = readtable(filename);
x2 = T{:,1} + days(T{:,2}); % Combining date and time
y2= T{:,3}; % Pressure data
plot(x2, y2, ‘b-‘, ‘LineWidth’, 1)
hold on
%% Load and plot data example 03
filename = ‘example3’;
T = readtable(filename);
x3 = T{:,1} + days(T{:,2}); % Combining date and time
y3= T{:,3}; % Pressure data
plot(x3, y3, ‘g-‘, ‘LineWidth’, 1)
hold on
%% Load and plot data example 04
filename = ‘example4’;
T = readtable(filename);
x4 = T{:,1} + days(T{:,2}); % Combining date and time
y4= T{:,3}; % Pressure data
plot(x4, y4, ‘k-‘, ‘LineWidth’, 1)
hold on
grid on
axis tight multiple files, graphics, plot MATLAB Answers — New Questions
Using OR in simulink
Hi Guys,
Im working on a timed traffic light system (which includes pedestrian lights) in matlab using relational operators and lamps. I am having trouble getting the red pedestrian light to remain on, at the time the main traffic light turns orange. I asked my lecturer about this, and he expalined that I need to use an OR operator to complete this system. I have tried integrating this into my simple system but cant seem to get the light to remain red and then turn off while the main lamp switches from orange to red. My traffic light works well apart from this section.
Please see attached simulink file to understand further what I am trying to do.
Thanks guys!
WilliamHi Guys,
Im working on a timed traffic light system (which includes pedestrian lights) in matlab using relational operators and lamps. I am having trouble getting the red pedestrian light to remain on, at the time the main traffic light turns orange. I asked my lecturer about this, and he expalined that I need to use an OR operator to complete this system. I have tried integrating this into my simple system but cant seem to get the light to remain red and then turn off while the main lamp switches from orange to red. My traffic light works well apart from this section.
Please see attached simulink file to understand further what I am trying to do.
Thanks guys!
William Hi Guys,
Im working on a timed traffic light system (which includes pedestrian lights) in matlab using relational operators and lamps. I am having trouble getting the red pedestrian light to remain on, at the time the main traffic light turns orange. I asked my lecturer about this, and he expalined that I need to use an OR operator to complete this system. I have tried integrating this into my simple system but cant seem to get the light to remain red and then turn off while the main lamp switches from orange to red. My traffic light works well apart from this section.
Please see attached simulink file to understand further what I am trying to do.
Thanks guys!
William simulink MATLAB Answers — New Questions
Optimizing problem: Convolution of two functions to dublicate a third one
Hello,
I am looking for a solution for a convolution problem. I have two time dependent functions (F1 and F2). One is a target function (F2). I want to convolute the other function (F1) with a mathematical model with two variables (Axial Dispersion model) so that I end up with a exact dublicate of the F2 function.
F2=F1 conv. AD
Within the axial dispersion model one position (t_mean) and one scattering parameter (Bo) shall be varriied so that the residual sum of squares should be minimized (optimization problem)
This is my code:
tic;
% Parameters of functions Y_Value_Fkt_XX
%BK
c0_tc1 = 0.06582;
k1 = 0.07932;
s1 = 0.09395;
tdead1 = 6.3016;
%KB80
c0_tc2 = 0.06466;
k2 = 0.08148;
s2 = 0.88691;
tdead2 = 6.8116;
% Time and function values
Time_vector = linspace(1, 100, 1200);
Time_matrix = reshape(Time_vector,[],1);
[rows, ~] = size(Time_matrix);
Y_Value_Fkt_BK = zeros(rows, 1);
Y_Value_Fkt_KB80 = zeros(rows, 1);
% Calculate function values
for i = 1:rows
Y_Value_Fkt_BK(i,1) = 0.5 * c0_tc1 * exp(k1 * (0.5 * k1 * s1 * s1 – (Time_matrix(i,1) – tdead1))) * erfc((k1 * s1 * s1 – (Time_matrix(i,1) – tdead1)) / (sqrt(2) * s1));
Y_Value_Fkt_KB80(i,1) = 0.5 * c0_tc2 * exp(k2 * (0.5 * k2 * s2 * s2 – (Time_matrix(i,1) – tdead2))) * erfc((k2 * s2 * s2 – (Time_matrix(i,1) – tdead2)) / (sqrt(2) * s2));
end
Y_Value_Fkt_KB80_Vektor=Y_Value_Fkt_KB80(:);
Y_Value_Fkt_BK_Vektor=Y_Value_Fkt_BK(:);
%Initialization of variables of Axial Dispersion Model
Bo_Values_Vector = linspace(0.0001, 0.2, 300);
Bo_Values = reshape(Bo_Values_Vector,[],1);
t_mean_Values_Vector = linspace(0.0001, 5, 300);
t_mean_Values = reshape(t_mean_Values_Vector,[],1);
% Resuts should be saved in
results = table();
% Calculation of Convolution
for j = 1:size(Bo_Values,1)
for k = 1:size(t_mean_Values,1)
Bo = Bo_Values(j);
t_mean = t_mean_Values(k);
% Calculation Y_Value_AD
Y_Value_AD=zeros(rows,1);
if Bo ~= 0
for l=1:size(Time_matrix,1)
Y_Value_AD(l) = 0.5 * sqrt(Bo / (pi * (Time_matrix(l) / t_mean))) .* exp(-(1 – (Time_matrix(l)/t_mean))^2 * Bo / (4 * (Time_matrix(l) / t_mean)));
end
else
Y_Value_AD(l)=NaN;
end
Y_Value_AD_Vektor=Y_Value_AD(:);
%Convolution
Conv_AD_BK=conv(Y_Value_AD_Vektor,Y_Value_Fkt_BK_Vektor,’same’);
%normalizing convolution
Integral_Conv_AD_BK=0;
for m=2:length(Time_matrix)
Area=0.5*(Time_matrix(m)-Time_matrix(m-1))*(Conv_AD_BK(m)+Conv_AD_BK(m-1));
Integral_Conv_AD_BK=Integral_Conv_AD_BK+Area;
end
Norm_Conv_AD_BK=Conv_AD_BK./Integral_Conv_AD_BK;
% RSS Calculation (Residual sum of squares)
RRsum = sum((Norm_Conv_AD_BK – Y_Value_Fkt_KB80).^2);
% Save
results = [results; table(Bo, t_mean, RRsum)];
end
end
%Find row where RSS=min
[minRRsum, minIndex] = min(results.RRsum);
minRow = results(minIndex, :);
%Find Bo and t_mean for RSS=min
minBo = minRow.Bo;
mint_mean = minRow.t_mean;
%Calculation of Y_Values and convolution for RSS=min values
Conv_min=zeros(rows,1);
Y_Value_AD_min=zeros(rows,1);
for i = 1:size(Time_matrix,1)
if mint_mean ~= 0
Y_Value_AD_min(i,1)= 0.5 * sqrt(minBo / (pi * (Time_matrix(i, 1) / mint_mean))) * exp(-(1 – Time_matrix(i, 1))^2 * minBo / (4 * (Time_matrix(i, 1) / mint_mean)));
else
Y_Value_AD_min(i, 1) = NaN;
end
end
Conv_min=conv(Y_Value_AD_min,Y_Value_Fkt_BK,’same’);
Integral_Conv_min=0;
for n=2:length(Time_matrix)
Area_min=0.5*(Time_matrix(n)-Time_matrix(n-1))*(Conv_min(n)+Conv_min(n-1));
Integral_Conv_min=Integral_Conv_min+Area_min;
end
Norm_Conv_min=Conv_min./Integral_Conv_min;
% control Plot
plot(Time_matrix, Y_Value_Fkt_BK, ‘b’, Time_matrix, Y_Value_Fkt_KB80, ‘r’, Time_matrix, Norm_Conv_min, ‘g’);
time=toc;
disp(time);
The following picture shows the result. Red is the target function, blue is the function which needs to be convoluted. green should be a duplicate of red if everything goes well.
Do you have any suggestions where a fault may be hidden or how to get a better fit?
Thanks in advance for your help :)Hello,
I am looking for a solution for a convolution problem. I have two time dependent functions (F1 and F2). One is a target function (F2). I want to convolute the other function (F1) with a mathematical model with two variables (Axial Dispersion model) so that I end up with a exact dublicate of the F2 function.
F2=F1 conv. AD
Within the axial dispersion model one position (t_mean) and one scattering parameter (Bo) shall be varriied so that the residual sum of squares should be minimized (optimization problem)
This is my code:
tic;
% Parameters of functions Y_Value_Fkt_XX
%BK
c0_tc1 = 0.06582;
k1 = 0.07932;
s1 = 0.09395;
tdead1 = 6.3016;
%KB80
c0_tc2 = 0.06466;
k2 = 0.08148;
s2 = 0.88691;
tdead2 = 6.8116;
% Time and function values
Time_vector = linspace(1, 100, 1200);
Time_matrix = reshape(Time_vector,[],1);
[rows, ~] = size(Time_matrix);
Y_Value_Fkt_BK = zeros(rows, 1);
Y_Value_Fkt_KB80 = zeros(rows, 1);
% Calculate function values
for i = 1:rows
Y_Value_Fkt_BK(i,1) = 0.5 * c0_tc1 * exp(k1 * (0.5 * k1 * s1 * s1 – (Time_matrix(i,1) – tdead1))) * erfc((k1 * s1 * s1 – (Time_matrix(i,1) – tdead1)) / (sqrt(2) * s1));
Y_Value_Fkt_KB80(i,1) = 0.5 * c0_tc2 * exp(k2 * (0.5 * k2 * s2 * s2 – (Time_matrix(i,1) – tdead2))) * erfc((k2 * s2 * s2 – (Time_matrix(i,1) – tdead2)) / (sqrt(2) * s2));
end
Y_Value_Fkt_KB80_Vektor=Y_Value_Fkt_KB80(:);
Y_Value_Fkt_BK_Vektor=Y_Value_Fkt_BK(:);
%Initialization of variables of Axial Dispersion Model
Bo_Values_Vector = linspace(0.0001, 0.2, 300);
Bo_Values = reshape(Bo_Values_Vector,[],1);
t_mean_Values_Vector = linspace(0.0001, 5, 300);
t_mean_Values = reshape(t_mean_Values_Vector,[],1);
% Resuts should be saved in
results = table();
% Calculation of Convolution
for j = 1:size(Bo_Values,1)
for k = 1:size(t_mean_Values,1)
Bo = Bo_Values(j);
t_mean = t_mean_Values(k);
% Calculation Y_Value_AD
Y_Value_AD=zeros(rows,1);
if Bo ~= 0
for l=1:size(Time_matrix,1)
Y_Value_AD(l) = 0.5 * sqrt(Bo / (pi * (Time_matrix(l) / t_mean))) .* exp(-(1 – (Time_matrix(l)/t_mean))^2 * Bo / (4 * (Time_matrix(l) / t_mean)));
end
else
Y_Value_AD(l)=NaN;
end
Y_Value_AD_Vektor=Y_Value_AD(:);
%Convolution
Conv_AD_BK=conv(Y_Value_AD_Vektor,Y_Value_Fkt_BK_Vektor,’same’);
%normalizing convolution
Integral_Conv_AD_BK=0;
for m=2:length(Time_matrix)
Area=0.5*(Time_matrix(m)-Time_matrix(m-1))*(Conv_AD_BK(m)+Conv_AD_BK(m-1));
Integral_Conv_AD_BK=Integral_Conv_AD_BK+Area;
end
Norm_Conv_AD_BK=Conv_AD_BK./Integral_Conv_AD_BK;
% RSS Calculation (Residual sum of squares)
RRsum = sum((Norm_Conv_AD_BK – Y_Value_Fkt_KB80).^2);
% Save
results = [results; table(Bo, t_mean, RRsum)];
end
end
%Find row where RSS=min
[minRRsum, minIndex] = min(results.RRsum);
minRow = results(minIndex, :);
%Find Bo and t_mean for RSS=min
minBo = minRow.Bo;
mint_mean = minRow.t_mean;
%Calculation of Y_Values and convolution for RSS=min values
Conv_min=zeros(rows,1);
Y_Value_AD_min=zeros(rows,1);
for i = 1:size(Time_matrix,1)
if mint_mean ~= 0
Y_Value_AD_min(i,1)= 0.5 * sqrt(minBo / (pi * (Time_matrix(i, 1) / mint_mean))) * exp(-(1 – Time_matrix(i, 1))^2 * minBo / (4 * (Time_matrix(i, 1) / mint_mean)));
else
Y_Value_AD_min(i, 1) = NaN;
end
end
Conv_min=conv(Y_Value_AD_min,Y_Value_Fkt_BK,’same’);
Integral_Conv_min=0;
for n=2:length(Time_matrix)
Area_min=0.5*(Time_matrix(n)-Time_matrix(n-1))*(Conv_min(n)+Conv_min(n-1));
Integral_Conv_min=Integral_Conv_min+Area_min;
end
Norm_Conv_min=Conv_min./Integral_Conv_min;
% control Plot
plot(Time_matrix, Y_Value_Fkt_BK, ‘b’, Time_matrix, Y_Value_Fkt_KB80, ‘r’, Time_matrix, Norm_Conv_min, ‘g’);
time=toc;
disp(time);
The following picture shows the result. Red is the target function, blue is the function which needs to be convoluted. green should be a duplicate of red if everything goes well.
Do you have any suggestions where a fault may be hidden or how to get a better fit?
Thanks in advance for your help 🙂 Hello,
I am looking for a solution for a convolution problem. I have two time dependent functions (F1 and F2). One is a target function (F2). I want to convolute the other function (F1) with a mathematical model with two variables (Axial Dispersion model) so that I end up with a exact dublicate of the F2 function.
F2=F1 conv. AD
Within the axial dispersion model one position (t_mean) and one scattering parameter (Bo) shall be varriied so that the residual sum of squares should be minimized (optimization problem)
This is my code:
tic;
% Parameters of functions Y_Value_Fkt_XX
%BK
c0_tc1 = 0.06582;
k1 = 0.07932;
s1 = 0.09395;
tdead1 = 6.3016;
%KB80
c0_tc2 = 0.06466;
k2 = 0.08148;
s2 = 0.88691;
tdead2 = 6.8116;
% Time and function values
Time_vector = linspace(1, 100, 1200);
Time_matrix = reshape(Time_vector,[],1);
[rows, ~] = size(Time_matrix);
Y_Value_Fkt_BK = zeros(rows, 1);
Y_Value_Fkt_KB80 = zeros(rows, 1);
% Calculate function values
for i = 1:rows
Y_Value_Fkt_BK(i,1) = 0.5 * c0_tc1 * exp(k1 * (0.5 * k1 * s1 * s1 – (Time_matrix(i,1) – tdead1))) * erfc((k1 * s1 * s1 – (Time_matrix(i,1) – tdead1)) / (sqrt(2) * s1));
Y_Value_Fkt_KB80(i,1) = 0.5 * c0_tc2 * exp(k2 * (0.5 * k2 * s2 * s2 – (Time_matrix(i,1) – tdead2))) * erfc((k2 * s2 * s2 – (Time_matrix(i,1) – tdead2)) / (sqrt(2) * s2));
end
Y_Value_Fkt_KB80_Vektor=Y_Value_Fkt_KB80(:);
Y_Value_Fkt_BK_Vektor=Y_Value_Fkt_BK(:);
%Initialization of variables of Axial Dispersion Model
Bo_Values_Vector = linspace(0.0001, 0.2, 300);
Bo_Values = reshape(Bo_Values_Vector,[],1);
t_mean_Values_Vector = linspace(0.0001, 5, 300);
t_mean_Values = reshape(t_mean_Values_Vector,[],1);
% Resuts should be saved in
results = table();
% Calculation of Convolution
for j = 1:size(Bo_Values,1)
for k = 1:size(t_mean_Values,1)
Bo = Bo_Values(j);
t_mean = t_mean_Values(k);
% Calculation Y_Value_AD
Y_Value_AD=zeros(rows,1);
if Bo ~= 0
for l=1:size(Time_matrix,1)
Y_Value_AD(l) = 0.5 * sqrt(Bo / (pi * (Time_matrix(l) / t_mean))) .* exp(-(1 – (Time_matrix(l)/t_mean))^2 * Bo / (4 * (Time_matrix(l) / t_mean)));
end
else
Y_Value_AD(l)=NaN;
end
Y_Value_AD_Vektor=Y_Value_AD(:);
%Convolution
Conv_AD_BK=conv(Y_Value_AD_Vektor,Y_Value_Fkt_BK_Vektor,’same’);
%normalizing convolution
Integral_Conv_AD_BK=0;
for m=2:length(Time_matrix)
Area=0.5*(Time_matrix(m)-Time_matrix(m-1))*(Conv_AD_BK(m)+Conv_AD_BK(m-1));
Integral_Conv_AD_BK=Integral_Conv_AD_BK+Area;
end
Norm_Conv_AD_BK=Conv_AD_BK./Integral_Conv_AD_BK;
% RSS Calculation (Residual sum of squares)
RRsum = sum((Norm_Conv_AD_BK – Y_Value_Fkt_KB80).^2);
% Save
results = [results; table(Bo, t_mean, RRsum)];
end
end
%Find row where RSS=min
[minRRsum, minIndex] = min(results.RRsum);
minRow = results(minIndex, :);
%Find Bo and t_mean for RSS=min
minBo = minRow.Bo;
mint_mean = minRow.t_mean;
%Calculation of Y_Values and convolution for RSS=min values
Conv_min=zeros(rows,1);
Y_Value_AD_min=zeros(rows,1);
for i = 1:size(Time_matrix,1)
if mint_mean ~= 0
Y_Value_AD_min(i,1)= 0.5 * sqrt(minBo / (pi * (Time_matrix(i, 1) / mint_mean))) * exp(-(1 – Time_matrix(i, 1))^2 * minBo / (4 * (Time_matrix(i, 1) / mint_mean)));
else
Y_Value_AD_min(i, 1) = NaN;
end
end
Conv_min=conv(Y_Value_AD_min,Y_Value_Fkt_BK,’same’);
Integral_Conv_min=0;
for n=2:length(Time_matrix)
Area_min=0.5*(Time_matrix(n)-Time_matrix(n-1))*(Conv_min(n)+Conv_min(n-1));
Integral_Conv_min=Integral_Conv_min+Area_min;
end
Norm_Conv_min=Conv_min./Integral_Conv_min;
% control Plot
plot(Time_matrix, Y_Value_Fkt_BK, ‘b’, Time_matrix, Y_Value_Fkt_KB80, ‘r’, Time_matrix, Norm_Conv_min, ‘g’);
time=toc;
disp(time);
The following picture shows the result. Red is the target function, blue is the function which needs to be convoluted. green should be a duplicate of red if everything goes well.
Do you have any suggestions where a fault may be hidden or how to get a better fit?
Thanks in advance for your help 🙂 convolution MATLAB Answers — New Questions
Why do I receive License Manager error -1 when running webapps-start for WebApp Server?
After I have installed and configured Web App Server and I attempt to run the script "webapp-start", I receive an error message:
Web App Server failed to start, please see the log files for more information.
When examining the Web App Server log files it states:
License Manager error -1, Cannot find the license file.
License Path:After I have installed and configured Web App Server and I attempt to run the script "webapp-start", I receive an error message:
Web App Server failed to start, please see the log files for more information.
When examining the Web App Server log files it states:
License Manager error -1, Cannot find the license file.
License Path: After I have installed and configured Web App Server and I attempt to run the script "webapp-start", I receive an error message:
Web App Server failed to start, please see the log files for more information.
When examining the Web App Server log files it states:
License Manager error -1, Cannot find the license file.
License Path: MATLAB Answers — New Questions
Warning: Matrix is singular to working precision in one line
The code seems working perfectly fine but one line it gives an error and does not produce a graph as it should be, could someone explain the error in line 54
% 2-D Source Panel Method
% Reads panel points from a text file and calculates flow around the body.
% Clear workspace and command window
clear;
clc;
% Read panel points from a text file
filename = ‘panel_points.txt’;
panel_points = load(filename);
% Number of panels
N = size(panel_points, 1) – 1;
% Panel coordinates
x = panel_points(:, 1);
y = panel_points(:, 2);
% Prompt user for flow conditions
U_inf = input(‘Enter the free stream velocity (U_inf): ‘);
alpha = input(‘Enter the angle of attack (alpha in degrees): ‘);
alpha = deg2rad(alpha);
% Initialize matrices
A = zeros(N+1, N+1);
RHS = zeros(N+1, 1);
% Calculate panel lengths and angles
for i = 1:N
x_mid(i) = 0.5 * (x(i) + x(i+1));
y_mid(i) = 0.5 * (y(i) + y(i+1));
s(i) = sqrt((x(i+1) – x(i))^2 + (y(i+1) – y(i))^2);
theta(i) = atan2(y(i+1) – y(i), x(i+1) – x(i));
end
% Populate influence coefficient matrix
for i = 1:N
for j = 1:N
if i == j
A(i,j) = 0.5;
else
A(i,j) = (1 / (2 * pi)) * log(sqrt((x_mid(i) – x(j))^2 + (y_mid(i) – y(j))^2) / sqrt((x_mid(i) – x(j+1))^2 + (y_mid(i) – y(j+1))^2));
end
end
RHS(i) = -U_inf * cos(theta(i) – alpha);
end
% Apply Kutta condition
A(N+1,1) = 1;
A(N+1,N) = -1;
RHS(N+1) = 0;
% Solve for source strengths
LINE54 sigma = A RHS;
% Calculate tangential velocity and pressure coefficient
for i = 1:N
V_t(i) = U_inf * sin(theta(i) – alpha) + sigma(i) – sigma(i+1);
Cp(i) = 1 – (V_t(i) / U_inf)^2;
end
% Plotting the pressure coefficient distribution
figure;
plot(x_mid, Cp, ‘-o’);
xlabel(‘x’);
ylabel(‘C_p’);
title(‘Pressure Coefficient Distribution’);
set(gca, ‘YDir’, ‘reverse’);
grid on;
disp(‘Computation complete. Pressure coefficient distribution plotted.’);
Enter the free stream velocity (U_inf): 30
Enter the angle of attack (alpha in degrees): 0
54 sigma = A RHS;
Warning: Matrix is singular to working precision.
> In untitled (line 54)
this is what I got and a blank graphThe code seems working perfectly fine but one line it gives an error and does not produce a graph as it should be, could someone explain the error in line 54
% 2-D Source Panel Method
% Reads panel points from a text file and calculates flow around the body.
% Clear workspace and command window
clear;
clc;
% Read panel points from a text file
filename = ‘panel_points.txt’;
panel_points = load(filename);
% Number of panels
N = size(panel_points, 1) – 1;
% Panel coordinates
x = panel_points(:, 1);
y = panel_points(:, 2);
% Prompt user for flow conditions
U_inf = input(‘Enter the free stream velocity (U_inf): ‘);
alpha = input(‘Enter the angle of attack (alpha in degrees): ‘);
alpha = deg2rad(alpha);
% Initialize matrices
A = zeros(N+1, N+1);
RHS = zeros(N+1, 1);
% Calculate panel lengths and angles
for i = 1:N
x_mid(i) = 0.5 * (x(i) + x(i+1));
y_mid(i) = 0.5 * (y(i) + y(i+1));
s(i) = sqrt((x(i+1) – x(i))^2 + (y(i+1) – y(i))^2);
theta(i) = atan2(y(i+1) – y(i), x(i+1) – x(i));
end
% Populate influence coefficient matrix
for i = 1:N
for j = 1:N
if i == j
A(i,j) = 0.5;
else
A(i,j) = (1 / (2 * pi)) * log(sqrt((x_mid(i) – x(j))^2 + (y_mid(i) – y(j))^2) / sqrt((x_mid(i) – x(j+1))^2 + (y_mid(i) – y(j+1))^2));
end
end
RHS(i) = -U_inf * cos(theta(i) – alpha);
end
% Apply Kutta condition
A(N+1,1) = 1;
A(N+1,N) = -1;
RHS(N+1) = 0;
% Solve for source strengths
LINE54 sigma = A RHS;
% Calculate tangential velocity and pressure coefficient
for i = 1:N
V_t(i) = U_inf * sin(theta(i) – alpha) + sigma(i) – sigma(i+1);
Cp(i) = 1 – (V_t(i) / U_inf)^2;
end
% Plotting the pressure coefficient distribution
figure;
plot(x_mid, Cp, ‘-o’);
xlabel(‘x’);
ylabel(‘C_p’);
title(‘Pressure Coefficient Distribution’);
set(gca, ‘YDir’, ‘reverse’);
grid on;
disp(‘Computation complete. Pressure coefficient distribution plotted.’);
Enter the free stream velocity (U_inf): 30
Enter the angle of attack (alpha in degrees): 0
54 sigma = A RHS;
Warning: Matrix is singular to working precision.
> In untitled (line 54)
this is what I got and a blank graph The code seems working perfectly fine but one line it gives an error and does not produce a graph as it should be, could someone explain the error in line 54
% 2-D Source Panel Method
% Reads panel points from a text file and calculates flow around the body.
% Clear workspace and command window
clear;
clc;
% Read panel points from a text file
filename = ‘panel_points.txt’;
panel_points = load(filename);
% Number of panels
N = size(panel_points, 1) – 1;
% Panel coordinates
x = panel_points(:, 1);
y = panel_points(:, 2);
% Prompt user for flow conditions
U_inf = input(‘Enter the free stream velocity (U_inf): ‘);
alpha = input(‘Enter the angle of attack (alpha in degrees): ‘);
alpha = deg2rad(alpha);
% Initialize matrices
A = zeros(N+1, N+1);
RHS = zeros(N+1, 1);
% Calculate panel lengths and angles
for i = 1:N
x_mid(i) = 0.5 * (x(i) + x(i+1));
y_mid(i) = 0.5 * (y(i) + y(i+1));
s(i) = sqrt((x(i+1) – x(i))^2 + (y(i+1) – y(i))^2);
theta(i) = atan2(y(i+1) – y(i), x(i+1) – x(i));
end
% Populate influence coefficient matrix
for i = 1:N
for j = 1:N
if i == j
A(i,j) = 0.5;
else
A(i,j) = (1 / (2 * pi)) * log(sqrt((x_mid(i) – x(j))^2 + (y_mid(i) – y(j))^2) / sqrt((x_mid(i) – x(j+1))^2 + (y_mid(i) – y(j+1))^2));
end
end
RHS(i) = -U_inf * cos(theta(i) – alpha);
end
% Apply Kutta condition
A(N+1,1) = 1;
A(N+1,N) = -1;
RHS(N+1) = 0;
% Solve for source strengths
LINE54 sigma = A RHS;
% Calculate tangential velocity and pressure coefficient
for i = 1:N
V_t(i) = U_inf * sin(theta(i) – alpha) + sigma(i) – sigma(i+1);
Cp(i) = 1 – (V_t(i) / U_inf)^2;
end
% Plotting the pressure coefficient distribution
figure;
plot(x_mid, Cp, ‘-o’);
xlabel(‘x’);
ylabel(‘C_p’);
title(‘Pressure Coefficient Distribution’);
set(gca, ‘YDir’, ‘reverse’);
grid on;
disp(‘Computation complete. Pressure coefficient distribution plotted.’);
Enter the free stream velocity (U_inf): 30
Enter the angle of attack (alpha in degrees): 0
54 sigma = A RHS;
Warning: Matrix is singular to working precision.
> In untitled (line 54)
this is what I got and a blank graph graph, singular, working, precision, warning MATLAB Answers — New Questions
Does I properly translate the equations in matlab code?
lambda = 2.75; %2.18; % Example initial guess for lambda
kappa_init = 0.0371; % 0.2; %0.0269; % 0.05 % Example initial guess for kappa
theta_k_init = 0.48; %0.3748; %*0.01745; %/0.0175;% 180/10; % 0.0007778*(pi/180); % Example initial guess for theta_k in radians
R_init = 450;% 347.3092; % 328.0456; %851.6597; % 349.4944; %362.4145; % Example initial guess for R
rout = 76.3; %76.3; %74.1783;%76.4; % Define rout
% Calculate omega_m and omega_p
omega_m = @(lambda, kappa, theta_k) sqrt(kappa / (2 * (lambda + 1))) * sqrt((lambda + 2) * cos(theta_k) – sqrt((lambda + 2)^2 * cos(theta_k)^2 – 4 * (lambda + 1)));
omega_p = @(lambda, kappa, theta_k) sqrt(kappa / (2 * (lambda + 1))) * sqrt((lambda + 2) * cos(theta_k) + sqrt((lambda + 2)^2 * cos(theta_k)^2 – 4 * (lambda + 1)));
% Define A1 and B1
A1 = @(R, kappa, lambda, theta_k, rout) ((8 * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 * omega_p(lambda, kappa, theta_k)^2)) / ((rout^2 – 4 * R^2)^2 * (kappa^2 + omega_m(lambda, kappa, theta_k)^2 * omega_p(lambda, kappa, theta_k)^2))) * …
(-2 * (omega_m(lambda, kappa, theta_k)^2 + omega_p(lambda, kappa, theta_k)^2) / (omega_m(lambda, kappa, theta_k)^2 * omega_p(lambda, kappa, theta_k)^2) …
+ rout * omega_m(lambda, kappa, theta_k)^2 * (kappa^2 – omega_p(lambda, kappa, theta_k)^4) / (kappa^2 * omega_p(lambda, kappa, theta_k) * (omega_m(lambda, kappa, theta_k)^2 – omega_p(lambda, kappa, theta_k)^2) * besselj(1, rout * omega_p(lambda, kappa, theta_k))) …
– rout * omega_p(lambda, kappa, theta_k)^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^4) / (kappa^2 * omega_m(lambda, kappa, theta_k) * (omega_m(lambda, kappa, theta_k)^2 – omega_p(lambda, kappa, theta_k)^2) * besselj(1, rout * omega_m(lambda, kappa, theta_k))));
B1 = @(R, kappa, lambda, theta_k, rout)((8 * R^2 * (kappa^2 – omega_m(kappa, theta_k, lambda)^2 * omega_p(kappa, theta_k, lambda)^2) * sqrt((kappa^2 – omega_m(kappa, theta_k, lambda)^4) * (kappa^2 – omega_p(kappa, theta_k, lambda)^4))) / …
((rout^2 – 4 * R^2)^2 * (kappa^2 + omega_m(kappa, theta_k, lambda)^2 * omega_p(kappa, theta_k, lambda)^2))) * …
(2 / (omega_m(kappa, theta_k, lambda)^2 * omega_p(kappa, theta_k, lambda)^2 * kappa) + rout / (kappa * omega_m(kappa, theta_k, lambda) * (omega_m(kappa, theta_k, lambda)^2 – omega_p(kappa, theta_k, lambda)^2) * besselj(1, rout * omega_m(kappa, theta_k, lambda))) …
– rout / (kappa * omega_p(kappa, theta_k, lambda) * (omega_m(kappa, theta_k, lambda)^2 – omega_p(kappa, theta_k, lambda)^2) * besselj(1, rout * omega_p(kappa, theta_k, lambda))));
dr = @(r_values, kappa,theta_k,R) …
(2 * besselj(1, r_values * omega_p(lambda, kappa, theta_k)) ./ …
((omega_m(lambda, kappa, theta_k)^2 – …
omega_p(lambda, kappa, theta_k)^2) * …
(kappa^2 + omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2))) .* …
((omega_m(lambda, kappa, theta_k)^2 * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4)) ./ …
omega_p(lambda, kappa, theta_k) .* …
(A1(R, kappa, lambda, theta_k, rout) + …
(16 * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2)) ./ …
(kappa^2 * omega_p(lambda, kappa, theta_k)^2 * …
(rout^2 – 4 * R^2)^2)) + (B1(R, kappa, lambda, theta_k, rout) …
* omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k) .* …
sqrt((kappa^2 – omega_m(lambda, kappa, theta_k)^4) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4))) ./ kappa) …
– (2 * besselj(1, r_values * omega_m(lambda, kappa, theta_k)) ./ …
((omega_m(lambda, kappa, theta_k)^2 – …
omega_p(lambda, kappa, theta_k)^2) * …
(kappa^2 + omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2))) .* …
((omega_p(lambda, kappa, theta_k)^2 * …
(kappa^2 – omega_m(lambda, kappa, theta_k)^4)) ./ …
omega_m(lambda, kappa, theta_k) .* …
(A1(R, kappa, lambda, theta_k, rout) + …
(16 * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2)) ./ …
(kappa^2 * omega_m(lambda, kappa, theta_k)^2 * …
(rout^2 – 4 * R^2)^2)) + (B1(R, kappa, lambda, theta_k, rout) …
* omega_m(lambda, kappa, theta_k) * …
omega_p(lambda, kappa, theta_k)^2 .* …
sqrt((kappa^2 – omega_m(lambda, kappa, theta_k)^4) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4))) ./ kappa) …
– (16 * r_values * R^2 * (omega_m(lambda, kappa, theta_k)^2 + …
omega_p(lambda, kappa, theta_k)^2) .* …
(kappa^2 – omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2)) ./ …
(omega_p(lambda, kappa, theta_k)^2 * …
omega_m(lambda, kappa, theta_k)^2 * …
(rout^2 – 4 * R^2)^2 * (kappa^2 + …
omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2));
dtheta = @(r_values, kappa,theta_k,R) …
(2 * besselj(1, r_values * omega_p(lambda, kappa, theta_k)) ./ …
((kappa^2 + omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2) * …
(omega_m(lambda, kappa, theta_k)^2 – …
omega_p(lambda, kappa, theta_k)^2))) .* …
(-sqrt((kappa^2 – omega_m(lambda, kappa, theta_k)^4) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4)) ./ …
omega_p(lambda, kappa, theta_k) .* …
(A1(R, kappa, lambda, theta_k, rout) * kappa + …
(16 * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 …
* omega_p(lambda, kappa, theta_k)^2)) ./ …
(kappa * omega_p(lambda, kappa, theta_k)^2 * …
(rout^2 – 4 * R^2)^2)) – B1(R, kappa, lambda, theta_k, rout) …
* omega_p(lambda, kappa, theta_k) * …
(kappa^2 – omega_m(lambda, kappa, theta_k)^4)) …
+ (2 * besselj(1, r_values * omega_m(lambda, kappa, theta_k)) ./ …
((kappa^2 + omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2) * …
(omega_m(lambda, kappa, theta_k)^2 – …
omega_p(lambda, kappa, theta_k)^2))) .* …
(sqrt((kappa^2 – omega_m(lambda, kappa, theta_k)^4) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4)) ./ …
omega_m(lambda, kappa, theta_k) .* …
(A1(R, kappa, lambda, theta_k, rout) * kappa + …
(16 * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2)) ./ …
(kappa * omega_m(lambda, kappa, theta_k)^2 * …
(rout^2 – 4 * R^2)^2)) + B1(R, kappa, lambda, theta_k, rout) * …
omega_m(lambda, kappa, theta_k) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4)) …
+ (16 * r_values * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 …
* omega_p(lambda, kappa, theta_k)^2) * …
sqrt((kappa^2 – omega_m(lambda, kappa, theta_k)^4) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4))) ./ …
(kappa * omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2 * (rout^2 – 4 * R^2)^2 * …
(kappa^2 + omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2));
% Plotting data
r_values = linspace(2.16, 75.6, 100).’; % specifying the range for r_values
% Plotting
figure;
Why at the boundary both the dr and dtheta are not reaching to zero? However, the analytical soln of the equations satisfied zero boundary condition. Did I make any mistake to translate those eqns (attached here in a separate file) in maltab code? Please someone suggest me the possible error (including brackets misplaced etc).lambda = 2.75; %2.18; % Example initial guess for lambda
kappa_init = 0.0371; % 0.2; %0.0269; % 0.05 % Example initial guess for kappa
theta_k_init = 0.48; %0.3748; %*0.01745; %/0.0175;% 180/10; % 0.0007778*(pi/180); % Example initial guess for theta_k in radians
R_init = 450;% 347.3092; % 328.0456; %851.6597; % 349.4944; %362.4145; % Example initial guess for R
rout = 76.3; %76.3; %74.1783;%76.4; % Define rout
% Calculate omega_m and omega_p
omega_m = @(lambda, kappa, theta_k) sqrt(kappa / (2 * (lambda + 1))) * sqrt((lambda + 2) * cos(theta_k) – sqrt((lambda + 2)^2 * cos(theta_k)^2 – 4 * (lambda + 1)));
omega_p = @(lambda, kappa, theta_k) sqrt(kappa / (2 * (lambda + 1))) * sqrt((lambda + 2) * cos(theta_k) + sqrt((lambda + 2)^2 * cos(theta_k)^2 – 4 * (lambda + 1)));
% Define A1 and B1
A1 = @(R, kappa, lambda, theta_k, rout) ((8 * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 * omega_p(lambda, kappa, theta_k)^2)) / ((rout^2 – 4 * R^2)^2 * (kappa^2 + omega_m(lambda, kappa, theta_k)^2 * omega_p(lambda, kappa, theta_k)^2))) * …
(-2 * (omega_m(lambda, kappa, theta_k)^2 + omega_p(lambda, kappa, theta_k)^2) / (omega_m(lambda, kappa, theta_k)^2 * omega_p(lambda, kappa, theta_k)^2) …
+ rout * omega_m(lambda, kappa, theta_k)^2 * (kappa^2 – omega_p(lambda, kappa, theta_k)^4) / (kappa^2 * omega_p(lambda, kappa, theta_k) * (omega_m(lambda, kappa, theta_k)^2 – omega_p(lambda, kappa, theta_k)^2) * besselj(1, rout * omega_p(lambda, kappa, theta_k))) …
– rout * omega_p(lambda, kappa, theta_k)^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^4) / (kappa^2 * omega_m(lambda, kappa, theta_k) * (omega_m(lambda, kappa, theta_k)^2 – omega_p(lambda, kappa, theta_k)^2) * besselj(1, rout * omega_m(lambda, kappa, theta_k))));
B1 = @(R, kappa, lambda, theta_k, rout)((8 * R^2 * (kappa^2 – omega_m(kappa, theta_k, lambda)^2 * omega_p(kappa, theta_k, lambda)^2) * sqrt((kappa^2 – omega_m(kappa, theta_k, lambda)^4) * (kappa^2 – omega_p(kappa, theta_k, lambda)^4))) / …
((rout^2 – 4 * R^2)^2 * (kappa^2 + omega_m(kappa, theta_k, lambda)^2 * omega_p(kappa, theta_k, lambda)^2))) * …
(2 / (omega_m(kappa, theta_k, lambda)^2 * omega_p(kappa, theta_k, lambda)^2 * kappa) + rout / (kappa * omega_m(kappa, theta_k, lambda) * (omega_m(kappa, theta_k, lambda)^2 – omega_p(kappa, theta_k, lambda)^2) * besselj(1, rout * omega_m(kappa, theta_k, lambda))) …
– rout / (kappa * omega_p(kappa, theta_k, lambda) * (omega_m(kappa, theta_k, lambda)^2 – omega_p(kappa, theta_k, lambda)^2) * besselj(1, rout * omega_p(kappa, theta_k, lambda))));
dr = @(r_values, kappa,theta_k,R) …
(2 * besselj(1, r_values * omega_p(lambda, kappa, theta_k)) ./ …
((omega_m(lambda, kappa, theta_k)^2 – …
omega_p(lambda, kappa, theta_k)^2) * …
(kappa^2 + omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2))) .* …
((omega_m(lambda, kappa, theta_k)^2 * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4)) ./ …
omega_p(lambda, kappa, theta_k) .* …
(A1(R, kappa, lambda, theta_k, rout) + …
(16 * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2)) ./ …
(kappa^2 * omega_p(lambda, kappa, theta_k)^2 * …
(rout^2 – 4 * R^2)^2)) + (B1(R, kappa, lambda, theta_k, rout) …
* omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k) .* …
sqrt((kappa^2 – omega_m(lambda, kappa, theta_k)^4) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4))) ./ kappa) …
– (2 * besselj(1, r_values * omega_m(lambda, kappa, theta_k)) ./ …
((omega_m(lambda, kappa, theta_k)^2 – …
omega_p(lambda, kappa, theta_k)^2) * …
(kappa^2 + omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2))) .* …
((omega_p(lambda, kappa, theta_k)^2 * …
(kappa^2 – omega_m(lambda, kappa, theta_k)^4)) ./ …
omega_m(lambda, kappa, theta_k) .* …
(A1(R, kappa, lambda, theta_k, rout) + …
(16 * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2)) ./ …
(kappa^2 * omega_m(lambda, kappa, theta_k)^2 * …
(rout^2 – 4 * R^2)^2)) + (B1(R, kappa, lambda, theta_k, rout) …
* omega_m(lambda, kappa, theta_k) * …
omega_p(lambda, kappa, theta_k)^2 .* …
sqrt((kappa^2 – omega_m(lambda, kappa, theta_k)^4) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4))) ./ kappa) …
– (16 * r_values * R^2 * (omega_m(lambda, kappa, theta_k)^2 + …
omega_p(lambda, kappa, theta_k)^2) .* …
(kappa^2 – omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2)) ./ …
(omega_p(lambda, kappa, theta_k)^2 * …
omega_m(lambda, kappa, theta_k)^2 * …
(rout^2 – 4 * R^2)^2 * (kappa^2 + …
omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2));
dtheta = @(r_values, kappa,theta_k,R) …
(2 * besselj(1, r_values * omega_p(lambda, kappa, theta_k)) ./ …
((kappa^2 + omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2) * …
(omega_m(lambda, kappa, theta_k)^2 – …
omega_p(lambda, kappa, theta_k)^2))) .* …
(-sqrt((kappa^2 – omega_m(lambda, kappa, theta_k)^4) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4)) ./ …
omega_p(lambda, kappa, theta_k) .* …
(A1(R, kappa, lambda, theta_k, rout) * kappa + …
(16 * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 …
* omega_p(lambda, kappa, theta_k)^2)) ./ …
(kappa * omega_p(lambda, kappa, theta_k)^2 * …
(rout^2 – 4 * R^2)^2)) – B1(R, kappa, lambda, theta_k, rout) …
* omega_p(lambda, kappa, theta_k) * …
(kappa^2 – omega_m(lambda, kappa, theta_k)^4)) …
+ (2 * besselj(1, r_values * omega_m(lambda, kappa, theta_k)) ./ …
((kappa^2 + omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2) * …
(omega_m(lambda, kappa, theta_k)^2 – …
omega_p(lambda, kappa, theta_k)^2))) .* …
(sqrt((kappa^2 – omega_m(lambda, kappa, theta_k)^4) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4)) ./ …
omega_m(lambda, kappa, theta_k) .* …
(A1(R, kappa, lambda, theta_k, rout) * kappa + …
(16 * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2)) ./ …
(kappa * omega_m(lambda, kappa, theta_k)^2 * …
(rout^2 – 4 * R^2)^2)) + B1(R, kappa, lambda, theta_k, rout) * …
omega_m(lambda, kappa, theta_k) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4)) …
+ (16 * r_values * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 …
* omega_p(lambda, kappa, theta_k)^2) * …
sqrt((kappa^2 – omega_m(lambda, kappa, theta_k)^4) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4))) ./ …
(kappa * omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2 * (rout^2 – 4 * R^2)^2 * …
(kappa^2 + omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2));
% Plotting data
r_values = linspace(2.16, 75.6, 100).’; % specifying the range for r_values
% Plotting
figure;
Why at the boundary both the dr and dtheta are not reaching to zero? However, the analytical soln of the equations satisfied zero boundary condition. Did I make any mistake to translate those eqns (attached here in a separate file) in maltab code? Please someone suggest me the possible error (including brackets misplaced etc). lambda = 2.75; %2.18; % Example initial guess for lambda
kappa_init = 0.0371; % 0.2; %0.0269; % 0.05 % Example initial guess for kappa
theta_k_init = 0.48; %0.3748; %*0.01745; %/0.0175;% 180/10; % 0.0007778*(pi/180); % Example initial guess for theta_k in radians
R_init = 450;% 347.3092; % 328.0456; %851.6597; % 349.4944; %362.4145; % Example initial guess for R
rout = 76.3; %76.3; %74.1783;%76.4; % Define rout
% Calculate omega_m and omega_p
omega_m = @(lambda, kappa, theta_k) sqrt(kappa / (2 * (lambda + 1))) * sqrt((lambda + 2) * cos(theta_k) – sqrt((lambda + 2)^2 * cos(theta_k)^2 – 4 * (lambda + 1)));
omega_p = @(lambda, kappa, theta_k) sqrt(kappa / (2 * (lambda + 1))) * sqrt((lambda + 2) * cos(theta_k) + sqrt((lambda + 2)^2 * cos(theta_k)^2 – 4 * (lambda + 1)));
% Define A1 and B1
A1 = @(R, kappa, lambda, theta_k, rout) ((8 * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 * omega_p(lambda, kappa, theta_k)^2)) / ((rout^2 – 4 * R^2)^2 * (kappa^2 + omega_m(lambda, kappa, theta_k)^2 * omega_p(lambda, kappa, theta_k)^2))) * …
(-2 * (omega_m(lambda, kappa, theta_k)^2 + omega_p(lambda, kappa, theta_k)^2) / (omega_m(lambda, kappa, theta_k)^2 * omega_p(lambda, kappa, theta_k)^2) …
+ rout * omega_m(lambda, kappa, theta_k)^2 * (kappa^2 – omega_p(lambda, kappa, theta_k)^4) / (kappa^2 * omega_p(lambda, kappa, theta_k) * (omega_m(lambda, kappa, theta_k)^2 – omega_p(lambda, kappa, theta_k)^2) * besselj(1, rout * omega_p(lambda, kappa, theta_k))) …
– rout * omega_p(lambda, kappa, theta_k)^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^4) / (kappa^2 * omega_m(lambda, kappa, theta_k) * (omega_m(lambda, kappa, theta_k)^2 – omega_p(lambda, kappa, theta_k)^2) * besselj(1, rout * omega_m(lambda, kappa, theta_k))));
B1 = @(R, kappa, lambda, theta_k, rout)((8 * R^2 * (kappa^2 – omega_m(kappa, theta_k, lambda)^2 * omega_p(kappa, theta_k, lambda)^2) * sqrt((kappa^2 – omega_m(kappa, theta_k, lambda)^4) * (kappa^2 – omega_p(kappa, theta_k, lambda)^4))) / …
((rout^2 – 4 * R^2)^2 * (kappa^2 + omega_m(kappa, theta_k, lambda)^2 * omega_p(kappa, theta_k, lambda)^2))) * …
(2 / (omega_m(kappa, theta_k, lambda)^2 * omega_p(kappa, theta_k, lambda)^2 * kappa) + rout / (kappa * omega_m(kappa, theta_k, lambda) * (omega_m(kappa, theta_k, lambda)^2 – omega_p(kappa, theta_k, lambda)^2) * besselj(1, rout * omega_m(kappa, theta_k, lambda))) …
– rout / (kappa * omega_p(kappa, theta_k, lambda) * (omega_m(kappa, theta_k, lambda)^2 – omega_p(kappa, theta_k, lambda)^2) * besselj(1, rout * omega_p(kappa, theta_k, lambda))));
dr = @(r_values, kappa,theta_k,R) …
(2 * besselj(1, r_values * omega_p(lambda, kappa, theta_k)) ./ …
((omega_m(lambda, kappa, theta_k)^2 – …
omega_p(lambda, kappa, theta_k)^2) * …
(kappa^2 + omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2))) .* …
((omega_m(lambda, kappa, theta_k)^2 * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4)) ./ …
omega_p(lambda, kappa, theta_k) .* …
(A1(R, kappa, lambda, theta_k, rout) + …
(16 * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2)) ./ …
(kappa^2 * omega_p(lambda, kappa, theta_k)^2 * …
(rout^2 – 4 * R^2)^2)) + (B1(R, kappa, lambda, theta_k, rout) …
* omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k) .* …
sqrt((kappa^2 – omega_m(lambda, kappa, theta_k)^4) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4))) ./ kappa) …
– (2 * besselj(1, r_values * omega_m(lambda, kappa, theta_k)) ./ …
((omega_m(lambda, kappa, theta_k)^2 – …
omega_p(lambda, kappa, theta_k)^2) * …
(kappa^2 + omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2))) .* …
((omega_p(lambda, kappa, theta_k)^2 * …
(kappa^2 – omega_m(lambda, kappa, theta_k)^4)) ./ …
omega_m(lambda, kappa, theta_k) .* …
(A1(R, kappa, lambda, theta_k, rout) + …
(16 * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2)) ./ …
(kappa^2 * omega_m(lambda, kappa, theta_k)^2 * …
(rout^2 – 4 * R^2)^2)) + (B1(R, kappa, lambda, theta_k, rout) …
* omega_m(lambda, kappa, theta_k) * …
omega_p(lambda, kappa, theta_k)^2 .* …
sqrt((kappa^2 – omega_m(lambda, kappa, theta_k)^4) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4))) ./ kappa) …
– (16 * r_values * R^2 * (omega_m(lambda, kappa, theta_k)^2 + …
omega_p(lambda, kappa, theta_k)^2) .* …
(kappa^2 – omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2)) ./ …
(omega_p(lambda, kappa, theta_k)^2 * …
omega_m(lambda, kappa, theta_k)^2 * …
(rout^2 – 4 * R^2)^2 * (kappa^2 + …
omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2));
dtheta = @(r_values, kappa,theta_k,R) …
(2 * besselj(1, r_values * omega_p(lambda, kappa, theta_k)) ./ …
((kappa^2 + omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2) * …
(omega_m(lambda, kappa, theta_k)^2 – …
omega_p(lambda, kappa, theta_k)^2))) .* …
(-sqrt((kappa^2 – omega_m(lambda, kappa, theta_k)^4) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4)) ./ …
omega_p(lambda, kappa, theta_k) .* …
(A1(R, kappa, lambda, theta_k, rout) * kappa + …
(16 * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 …
* omega_p(lambda, kappa, theta_k)^2)) ./ …
(kappa * omega_p(lambda, kappa, theta_k)^2 * …
(rout^2 – 4 * R^2)^2)) – B1(R, kappa, lambda, theta_k, rout) …
* omega_p(lambda, kappa, theta_k) * …
(kappa^2 – omega_m(lambda, kappa, theta_k)^4)) …
+ (2 * besselj(1, r_values * omega_m(lambda, kappa, theta_k)) ./ …
((kappa^2 + omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2) * …
(omega_m(lambda, kappa, theta_k)^2 – …
omega_p(lambda, kappa, theta_k)^2))) .* …
(sqrt((kappa^2 – omega_m(lambda, kappa, theta_k)^4) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4)) ./ …
omega_m(lambda, kappa, theta_k) .* …
(A1(R, kappa, lambda, theta_k, rout) * kappa + …
(16 * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2)) ./ …
(kappa * omega_m(lambda, kappa, theta_k)^2 * …
(rout^2 – 4 * R^2)^2)) + B1(R, kappa, lambda, theta_k, rout) * …
omega_m(lambda, kappa, theta_k) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4)) …
+ (16 * r_values * R^2 * (kappa^2 – omega_m(lambda, kappa, theta_k)^2 …
* omega_p(lambda, kappa, theta_k)^2) * …
sqrt((kappa^2 – omega_m(lambda, kappa, theta_k)^4) * …
(kappa^2 – omega_p(lambda, kappa, theta_k)^4))) ./ …
(kappa * omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2 * (rout^2 – 4 * R^2)^2 * …
(kappa^2 + omega_m(lambda, kappa, theta_k)^2 * …
omega_p(lambda, kappa, theta_k)^2));
% Plotting data
r_values = linspace(2.16, 75.6, 100).’; % specifying the range for r_values
% Plotting
figure;
Why at the boundary both the dr and dtheta are not reaching to zero? However, the analytical soln of the equations satisfied zero boundary condition. Did I make any mistake to translate those eqns (attached here in a separate file) in maltab code? Please someone suggest me the possible error (including brackets misplaced etc). eqns, code MATLAB Answers — New Questions