Month: January 2025
How can i simulate a system that have modeled by openmodelica in matlab freely not by dymola matlab interface and fmu?
Hi friends,
I want to use the model that have modeled by OpenModelica in MATLAB. But i need to do this freely not by fmu MATLAB toolbox or dymola Matlab interface. Could you please guide me how?
Can i generate *.dll file by openmodelica and then use this *.dll file in matlab s-function.
I am a beginner in modelica.
Thanks for your attention.Hi friends,
I want to use the model that have modeled by OpenModelica in MATLAB. But i need to do this freely not by fmu MATLAB toolbox or dymola Matlab interface. Could you please guide me how?
Can i generate *.dll file by openmodelica and then use this *.dll file in matlab s-function.
I am a beginner in modelica.
Thanks for your attention. Hi friends,
I want to use the model that have modeled by OpenModelica in MATLAB. But i need to do this freely not by fmu MATLAB toolbox or dymola Matlab interface. Could you please guide me how?
Can i generate *.dll file by openmodelica and then use this *.dll file in matlab s-function.
I am a beginner in modelica.
Thanks for your attention. modelica matlab interface MATLAB Answers — New Questions
How to draw a combined efficiency map
Hi expert,
I have two effiency maps, one for engine and one for generator and their operating curves like below. I want to obtain the maximum efficiency data, that is when speed from 0~600 rad/s, torque = the smaller value of maximum torque of genrator and engine(torque limitation), and effiency = efficiency of genrator * efficiency of engine.
The data file sizes are:
w_eg_row: 1*9 genrator speed
T_eg_col: 15*1 generator torque
eta_EG_map: 9*15 efficiency of generator
T_EG_max: 9*1 maximum torque versus speed
w_ce_row: 1*15 genrator speed
T_ce_col: 1*16 generator torque
eta_ce_map: 16*15 efficiency of generator
T_ce_max: 1*15 maximum torque versus speed
I don’t know how to process the data to get the result. Could you please provide the code?Hi expert,
I have two effiency maps, one for engine and one for generator and their operating curves like below. I want to obtain the maximum efficiency data, that is when speed from 0~600 rad/s, torque = the smaller value of maximum torque of genrator and engine(torque limitation), and effiency = efficiency of genrator * efficiency of engine.
The data file sizes are:
w_eg_row: 1*9 genrator speed
T_eg_col: 15*1 generator torque
eta_EG_map: 9*15 efficiency of generator
T_EG_max: 9*1 maximum torque versus speed
w_ce_row: 1*15 genrator speed
T_ce_col: 1*16 generator torque
eta_ce_map: 16*15 efficiency of generator
T_ce_max: 1*15 maximum torque versus speed
I don’t know how to process the data to get the result. Could you please provide the code? Hi expert,
I have two effiency maps, one for engine and one for generator and their operating curves like below. I want to obtain the maximum efficiency data, that is when speed from 0~600 rad/s, torque = the smaller value of maximum torque of genrator and engine(torque limitation), and effiency = efficiency of genrator * efficiency of engine.
The data file sizes are:
w_eg_row: 1*9 genrator speed
T_eg_col: 15*1 generator torque
eta_EG_map: 9*15 efficiency of generator
T_EG_max: 9*1 maximum torque versus speed
w_ce_row: 1*15 genrator speed
T_ce_col: 1*16 generator torque
eta_ce_map: 16*15 efficiency of generator
T_ce_max: 1*15 maximum torque versus speed
I don’t know how to process the data to get the result. Could you please provide the code? efficiency map MATLAB Answers — New Questions
Difficulty Getting to MPP via Incremental Conductance on Simulink.
%CODE
function out = fcn(V, I, Vo, Io, d, step)
dv = V – Vo;
di = I – Io;
if(dv == 0)
if(di == 0)
out = d;
else
if(di > 0)
%increase duty cycle
d=d-step;
else
%decrease duty cycle
d=d+step;
end
out = d;
end
else
if(di/dv == -(I/V))
out = d;
else
if(di/dv > -(I/V))
%decrease duty cycle
d=d-step;
else
%increase duty cycle
d=d+step;
end
out = d;
end
end
%CODE
We have this model for Inc Cond for solar panel MPPT project. The code is also provided for the block, our output used to be perfect when our power gui was set to 1e-7 but our other models are using 1e-6 and we have tried messing with the step size constant to no avail. We are unsure what is going on, if it is relevant we are using a synchronous buck converter for the output of our solar panel.%CODE
function out = fcn(V, I, Vo, Io, d, step)
dv = V – Vo;
di = I – Io;
if(dv == 0)
if(di == 0)
out = d;
else
if(di > 0)
%increase duty cycle
d=d-step;
else
%decrease duty cycle
d=d+step;
end
out = d;
end
else
if(di/dv == -(I/V))
out = d;
else
if(di/dv > -(I/V))
%decrease duty cycle
d=d-step;
else
%increase duty cycle
d=d+step;
end
out = d;
end
end
%CODE
We have this model for Inc Cond for solar panel MPPT project. The code is also provided for the block, our output used to be perfect when our power gui was set to 1e-7 but our other models are using 1e-6 and we have tried messing with the step size constant to no avail. We are unsure what is going on, if it is relevant we are using a synchronous buck converter for the output of our solar panel. %CODE
function out = fcn(V, I, Vo, Io, d, step)
dv = V – Vo;
di = I – Io;
if(dv == 0)
if(di == 0)
out = d;
else
if(di > 0)
%increase duty cycle
d=d-step;
else
%decrease duty cycle
d=d+step;
end
out = d;
end
else
if(di/dv == -(I/V))
out = d;
else
if(di/dv > -(I/V))
%decrease duty cycle
d=d-step;
else
%increase duty cycle
d=d+step;
end
out = d;
end
end
%CODE
We have this model for Inc Cond for solar panel MPPT project. The code is also provided for the block, our output used to be perfect when our power gui was set to 1e-7 but our other models are using 1e-6 and we have tried messing with the step size constant to no avail. We are unsure what is going on, if it is relevant we are using a synchronous buck converter for the output of our solar panel. mppt, simulink, inccond MATLAB Answers — New Questions
automating many column headings in table
I have a 10000×400 matrix, plotphys, I want to turn into a table and add variable names to. I understand that can be done easily with the array2table function. However adding 400 headings is a lot; luckily I want the headings uniform in that they would be labeled
‘phys state at tstep 1’, ‘phys state at tstep 2’, …, ‘phys state at tstep 400’
Is there a way I can basically automate the creation of the headings?
I tried this
head = join("phys state at tstep " + [1:1:400]);
phystable = array2table(plotphys, ‘VariableNames’, {head});
but that did not workI have a 10000×400 matrix, plotphys, I want to turn into a table and add variable names to. I understand that can be done easily with the array2table function. However adding 400 headings is a lot; luckily I want the headings uniform in that they would be labeled
‘phys state at tstep 1’, ‘phys state at tstep 2’, …, ‘phys state at tstep 400’
Is there a way I can basically automate the creation of the headings?
I tried this
head = join("phys state at tstep " + [1:1:400]);
phystable = array2table(plotphys, ‘VariableNames’, {head});
but that did not work I have a 10000×400 matrix, plotphys, I want to turn into a table and add variable names to. I understand that can be done easily with the array2table function. However adding 400 headings is a lot; luckily I want the headings uniform in that they would be labeled
‘phys state at tstep 1’, ‘phys state at tstep 2’, …, ‘phys state at tstep 400’
Is there a way I can basically automate the creation of the headings?
I tried this
head = join("phys state at tstep " + [1:1:400]);
phystable = array2table(plotphys, ‘VariableNames’, {head});
but that did not work table, headings MATLAB Answers — New Questions
Error OF C2000 in TMS320F28335
Dear Sir or Madam
I am writing to thank you for the sample program for the simulation of the Texas Instruments c2000 with the f28335 model. However, But I changed the blocks to the model f28335 and finally the error came with the following response..
I would be grateful if you could provide me with the model I need. Thank you very much for your help.
Sincerely
Mohsen Teimoori
"Error evaluating ‘InitFcn’ callback of ADC Type 3-5 block (mask) ‘f28335_sixstep_controlBLDC/Current Control/Sensor Driver Blocks/Sensor Driver Blocks (codegen)/Current Measurment/ADC5’.
Callback string is ‘validatePiccoloADC;
codertarget.registry.registerPiccoloADCBlocks(gcb);’
Caused by:
The values of the parameter SOC trigger on the blocks ADC5 and ADC5 must be different."Dear Sir or Madam
I am writing to thank you for the sample program for the simulation of the Texas Instruments c2000 with the f28335 model. However, But I changed the blocks to the model f28335 and finally the error came with the following response..
I would be grateful if you could provide me with the model I need. Thank you very much for your help.
Sincerely
Mohsen Teimoori
"Error evaluating ‘InitFcn’ callback of ADC Type 3-5 block (mask) ‘f28335_sixstep_controlBLDC/Current Control/Sensor Driver Blocks/Sensor Driver Blocks (codegen)/Current Measurment/ADC5’.
Callback string is ‘validatePiccoloADC;
codertarget.registry.registerPiccoloADCBlocks(gcb);’
Caused by:
The values of the parameter SOC trigger on the blocks ADC5 and ADC5 must be different." Dear Sir or Madam
I am writing to thank you for the sample program for the simulation of the Texas Instruments c2000 with the f28335 model. However, But I changed the blocks to the model f28335 and finally the error came with the following response..
I would be grateful if you could provide me with the model I need. Thank you very much for your help.
Sincerely
Mohsen Teimoori
"Error evaluating ‘InitFcn’ callback of ADC Type 3-5 block (mask) ‘f28335_sixstep_controlBLDC/Current Control/Sensor Driver Blocks/Sensor Driver Blocks (codegen)/Current Measurment/ADC5’.
Callback string is ‘validatePiccoloADC;
codertarget.registry.registerPiccoloADCBlocks(gcb);’
Caused by:
The values of the parameter SOC trigger on the blocks ADC5 and ADC5 must be different." c2000 and bldc motor control MATLAB Answers — New Questions
Finding specific peaks and valleys
I have a periodic signal with 6 peaks and 6 valleys. I am able to find all 6 peaks and all 6 valleys using the code below:
% plot periodic signal
plot(angle,signal)
hold on;
% fit to avoid noisy oscillations and find 6 global peaks
f = fit(angle,signal,’sin9′);
yfitted = feval(f,angle);
plot(angle,yfitted,’r’)
% find peaks and corresponding angles
[ypk0,idx0] = findpeaks(yfitted);
peaks = signal(idx0);
max_angles = angle(idx0);
% invert fitted signal to find 6 global valleys and corresponding angles
yfittedinv = max(yfitted) – yfitted;
[ypk,idx] = findpeaks(yfittedinv);
valleys = signal(idx);
min_angles = angle(idx);
Furthermore, I am able to find the global minimum (i.e., the lowest valley) using this line:
% find the global minimum
minangle = min_angles(valleys == min(valleys));
Both the arrays "max_angles" and "min_angles" have 6 elements. The question is how to reduce the number of elements in the array "min_angles" from 6 to 3, where I will have only the global minimum and the 2 non-neighbor valleys. The attached pic should help. I am able to find the green circle, but I also need to find the 2 red circles. Note that the global valley (green circle) is not always in the middle. It can be the first element of the array "min_angles", or it can be the last one. In the picture below, it’s number 4.I have a periodic signal with 6 peaks and 6 valleys. I am able to find all 6 peaks and all 6 valleys using the code below:
% plot periodic signal
plot(angle,signal)
hold on;
% fit to avoid noisy oscillations and find 6 global peaks
f = fit(angle,signal,’sin9′);
yfitted = feval(f,angle);
plot(angle,yfitted,’r’)
% find peaks and corresponding angles
[ypk0,idx0] = findpeaks(yfitted);
peaks = signal(idx0);
max_angles = angle(idx0);
% invert fitted signal to find 6 global valleys and corresponding angles
yfittedinv = max(yfitted) – yfitted;
[ypk,idx] = findpeaks(yfittedinv);
valleys = signal(idx);
min_angles = angle(idx);
Furthermore, I am able to find the global minimum (i.e., the lowest valley) using this line:
% find the global minimum
minangle = min_angles(valleys == min(valleys));
Both the arrays "max_angles" and "min_angles" have 6 elements. The question is how to reduce the number of elements in the array "min_angles" from 6 to 3, where I will have only the global minimum and the 2 non-neighbor valleys. The attached pic should help. I am able to find the green circle, but I also need to find the 2 red circles. Note that the global valley (green circle) is not always in the middle. It can be the first element of the array "min_angles", or it can be the last one. In the picture below, it’s number 4. I have a periodic signal with 6 peaks and 6 valleys. I am able to find all 6 peaks and all 6 valleys using the code below:
% plot periodic signal
plot(angle,signal)
hold on;
% fit to avoid noisy oscillations and find 6 global peaks
f = fit(angle,signal,’sin9′);
yfitted = feval(f,angle);
plot(angle,yfitted,’r’)
% find peaks and corresponding angles
[ypk0,idx0] = findpeaks(yfitted);
peaks = signal(idx0);
max_angles = angle(idx0);
% invert fitted signal to find 6 global valleys and corresponding angles
yfittedinv = max(yfitted) – yfitted;
[ypk,idx] = findpeaks(yfittedinv);
valleys = signal(idx);
min_angles = angle(idx);
Furthermore, I am able to find the global minimum (i.e., the lowest valley) using this line:
% find the global minimum
minangle = min_angles(valleys == min(valleys));
Both the arrays "max_angles" and "min_angles" have 6 elements. The question is how to reduce the number of elements in the array "min_angles" from 6 to 3, where I will have only the global minimum and the 2 non-neighbor valleys. The attached pic should help. I am able to find the green circle, but I also need to find the 2 red circles. Note that the global valley (green circle) is not always in the middle. It can be the first element of the array "min_angles", or it can be the last one. In the picture below, it’s number 4. findpeaks, findvalleys MATLAB Answers — New Questions
Unable to Install MatLab via SYSTEM Account
I have been trying to deploy MATLAB R2023b to Windows 10 PC’s in our organization, using remote Powershell scripts which run under SYSTEM credentials. However, the installation always hangs, fairly close to the end. The mathworks_install.log shows the last log as ‘Installing MathWorks Service Host’, which is where it seems to hang indefinitely.
From what I can see, when installing MATLAB in a user context, the Service Host would be installed to C:Users%username%AppDataLocalMathWorksServiceHost. I am guessing that the MATLAB installer has a problem with this when running as SYSTEM. Does anyone have any advice on how we might get around this? As far as I can tell, any user who logs into the PC and opens MATLAB will have the Service Host installed under their profile – so I don’t think it is necessary for this to be done during the initial installation? I would take any suggestion which would allow the installation routine to complete.I have been trying to deploy MATLAB R2023b to Windows 10 PC’s in our organization, using remote Powershell scripts which run under SYSTEM credentials. However, the installation always hangs, fairly close to the end. The mathworks_install.log shows the last log as ‘Installing MathWorks Service Host’, which is where it seems to hang indefinitely.
From what I can see, when installing MATLAB in a user context, the Service Host would be installed to C:Users%username%AppDataLocalMathWorksServiceHost. I am guessing that the MATLAB installer has a problem with this when running as SYSTEM. Does anyone have any advice on how we might get around this? As far as I can tell, any user who logs into the PC and opens MATLAB will have the Service Host installed under their profile – so I don’t think it is necessary for this to be done during the initial installation? I would take any suggestion which would allow the installation routine to complete. I have been trying to deploy MATLAB R2023b to Windows 10 PC’s in our organization, using remote Powershell scripts which run under SYSTEM credentials. However, the installation always hangs, fairly close to the end. The mathworks_install.log shows the last log as ‘Installing MathWorks Service Host’, which is where it seems to hang indefinitely.
From what I can see, when installing MATLAB in a user context, the Service Host would be installed to C:Users%username%AppDataLocalMathWorksServiceHost. I am guessing that the MATLAB installer has a problem with this when running as SYSTEM. Does anyone have any advice on how we might get around this? As far as I can tell, any user who logs into the PC and opens MATLAB will have the Service Host installed under their profile – so I don’t think it is necessary for this to be done during the initial installation? I would take any suggestion which would allow the installation routine to complete. installation, service host, mathworks service host, r2023b MATLAB Answers — New Questions
I am trying to use matlab with refprop, but it shows [SETUP error 101] error in opening file for component # 1; filename = (C:Program Files (x86)REFPROPfluidsfluid.fld).
fluid=’cyclopentane’
T1=348.15;
P1=refpropm(‘P’,’T’,T1,’Q’,1,’fluid’);fluid=’cyclopentane’
T1=348.15;
P1=refpropm(‘P’,’T’,T1,’Q’,1,’fluid’); fluid=’cyclopentane’
T1=348.15;
P1=refpropm(‘P’,’T’,T1,’Q’,1,’fluid’); refprop, [setup error 101] MATLAB Answers — New Questions
How to resolve unsupported functions in MATLAB HDL Coder?
Hello,
We have some simulation code written in MATLAB that we are trying to simulate and deploy on an FPGA, and so we are trying to use the HDL Coder tool for this task. However, we are receiving code generation issues indicating that the following functions are not supported:
diff
fft
exp
angle
ifft
filter
Is there perhaps a toolkit or package that replicates these functions with support for HDL coding? I tried referencing the list of supported functions found here:
https://www.mathworks.com/help/hdlcoder/ug/functions-supported-for-hdl-code-generation-alphabetical-list.html
But the links for supported functions don’t seem to be working (at least for me).
Otherwise, is there a recommended way of resolving this?
Thank you,
James
P.S. I have successfully used the MATLAB Coder to generate C code for this project, if this helps.Hello,
We have some simulation code written in MATLAB that we are trying to simulate and deploy on an FPGA, and so we are trying to use the HDL Coder tool for this task. However, we are receiving code generation issues indicating that the following functions are not supported:
diff
fft
exp
angle
ifft
filter
Is there perhaps a toolkit or package that replicates these functions with support for HDL coding? I tried referencing the list of supported functions found here:
https://www.mathworks.com/help/hdlcoder/ug/functions-supported-for-hdl-code-generation-alphabetical-list.html
But the links for supported functions don’t seem to be working (at least for me).
Otherwise, is there a recommended way of resolving this?
Thank you,
James
P.S. I have successfully used the MATLAB Coder to generate C code for this project, if this helps. Hello,
We have some simulation code written in MATLAB that we are trying to simulate and deploy on an FPGA, and so we are trying to use the HDL Coder tool for this task. However, we are receiving code generation issues indicating that the following functions are not supported:
diff
fft
exp
angle
ifft
filter
Is there perhaps a toolkit or package that replicates these functions with support for HDL coding? I tried referencing the list of supported functions found here:
https://www.mathworks.com/help/hdlcoder/ug/functions-supported-for-hdl-code-generation-alphabetical-list.html
But the links for supported functions don’t seem to be working (at least for me).
Otherwise, is there a recommended way of resolving this?
Thank you,
James
P.S. I have successfully used the MATLAB Coder to generate C code for this project, if this helps. fft, matlab code MATLAB Answers — New Questions
FGETL taking a long time to execute
I am running fgetl in a loop similar to the code below. When profiling the code, I noticed that fgetl(fid) takes the most time to execute compared to the rest of the code. After checking the fgetl documentation, I found the following note in the documentation:
fgetl is intended for use with files that contain newline characters. Given a file with no newline characters, fgetl may take a long time to execute.
However, the documentation does not provide a solution for files without newline characters. Since my file lacks newline characters, what would be the best alternative to fgetl?
fid = fopen(FileName);
while ischar(tline) %loops over 1e5 times
% read new line
tic
tline = fgetl(fid);
toc
% Do stuff with tline
endI am running fgetl in a loop similar to the code below. When profiling the code, I noticed that fgetl(fid) takes the most time to execute compared to the rest of the code. After checking the fgetl documentation, I found the following note in the documentation:
fgetl is intended for use with files that contain newline characters. Given a file with no newline characters, fgetl may take a long time to execute.
However, the documentation does not provide a solution for files without newline characters. Since my file lacks newline characters, what would be the best alternative to fgetl?
fid = fopen(FileName);
while ischar(tline) %loops over 1e5 times
% read new line
tic
tline = fgetl(fid);
toc
% Do stuff with tline
end I am running fgetl in a loop similar to the code below. When profiling the code, I noticed that fgetl(fid) takes the most time to execute compared to the rest of the code. After checking the fgetl documentation, I found the following note in the documentation:
fgetl is intended for use with files that contain newline characters. Given a file with no newline characters, fgetl may take a long time to execute.
However, the documentation does not provide a solution for files without newline characters. Since my file lacks newline characters, what would be the best alternative to fgetl?
fid = fopen(FileName);
while ischar(tline) %loops over 1e5 times
% read new line
tic
tline = fgetl(fid);
toc
% Do stuff with tline
end fgetl, fgets, loop MATLAB Answers — New Questions
Increase the plotting performance in the MATLAB level (drawmode/ optimizing rendering/ down sampling etc)
*Problem statement*: Increase the plotting performance in the MATLAB level (drawmode/ optimizing rendering/ down sampling etc)
*Background*: We are working on a MATLAB based framework for analysis and visualization of data. The information that we use for plotting is very huge. The number of data points are in the range of ~10E7 or more and we are facing MATLAB performance issues when we zoom/pan/maximize/minimize. We urgently need to improve the performance. The requirement is to have the complete information in the plot but the end user chooses to enable or disable particular lines based on the need. As a framework owner we do not have any control on the number of data points that are used for the plot or remove the overlapping points.
Bottom line is we cannot modify the data to be plotted so we will continue to have huge number of points. We can only try from the MATLAB layer to increase the performance as requested above.
Please help us to improve the performance with your experience.
Looking forward for your answers.
Thanks,
Dhanya*Problem statement*: Increase the plotting performance in the MATLAB level (drawmode/ optimizing rendering/ down sampling etc)
*Background*: We are working on a MATLAB based framework for analysis and visualization of data. The information that we use for plotting is very huge. The number of data points are in the range of ~10E7 or more and we are facing MATLAB performance issues when we zoom/pan/maximize/minimize. We urgently need to improve the performance. The requirement is to have the complete information in the plot but the end user chooses to enable or disable particular lines based on the need. As a framework owner we do not have any control on the number of data points that are used for the plot or remove the overlapping points.
Bottom line is we cannot modify the data to be plotted so we will continue to have huge number of points. We can only try from the MATLAB layer to increase the performance as requested above.
Please help us to improve the performance with your experience.
Looking forward for your answers.
Thanks,
Dhanya *Problem statement*: Increase the plotting performance in the MATLAB level (drawmode/ optimizing rendering/ down sampling etc)
*Background*: We are working on a MATLAB based framework for analysis and visualization of data. The information that we use for plotting is very huge. The number of data points are in the range of ~10E7 or more and we are facing MATLAB performance issues when we zoom/pan/maximize/minimize. We urgently need to improve the performance. The requirement is to have the complete information in the plot but the end user chooses to enable or disable particular lines based on the need. As a framework owner we do not have any control on the number of data points that are used for the plot or remove the overlapping points.
Bottom line is we cannot modify the data to be plotted so we will continue to have huge number of points. We can only try from the MATLAB layer to increase the performance as requested above.
Please help us to improve the performance with your experience.
Looking forward for your answers.
Thanks,
Dhanya matlab plot performance, performance, hg1, hg2 MATLAB Answers — New Questions
How to simulate permanent magnets using the PDE Toolbox in R2025a
I am trying to model and visualize two permanent magnet spheres using the below code snippet:
function twoMagnets_femodel_demo()
clc; clear; close all;
% ——————————-
% 1) Define geometry parameters
% ——————————-
% Let’s assume "1/2-inch magnets" => diameter = 0.5 inch => radius = 0.25 in
% 1 inch ~ 0.0254 m, so 0.25 in ~ 0.00635 m
R_sphere = 0.00635; % [m]
% Bounding box of ~5 cm each side
boxDim = 0.05; % [m]
% ——————————-
% 2) Build geometry parts
% ——————————-
% (a) Air region: bounding box
boxGm = multicuboid(boxDim, boxDim, boxDim);
% (b) Sphere #1
sphere1Gm = multisphere(R_sphere);
% (c) Sphere #2
sphere2Gm = multisphere(R_sphere);
% Translate spheres so that they’re centered in the box, side-by-side
% Let the box corners go from (0,0,0) to (0.05,0.05,0.05), so center ~ (0.025,0.025,0.025)
centerBox = [0.025, 0.025, 0.025];
offset1 = centerBox + [-R_sphere, 0, 0]; % shift left in x
offset2 = centerBox + [ R_sphere, 0, 0]; % shift right in x
sphere1Gm = translate(sphere1Gm, offset1);
sphere2Gm = translate(sphere2Gm, offset2);
% ——————————-
% 3) Combine geometries
% ——————————-
% addCell(…) is the new PDE Toolbox function that
% keeps each shape as a separate "cell" in the final geometry.
gm = addCell(boxGm, sphere1Gm);
gm = addCell(gm, sphere2Gm);
% Visualize & label
figure;
pdegplot(gm, FaceAlpha=0.2, CellLabels="on");
title("Bounding Box + Two Spheres");
axis equal
% At this point we should see "Cell #1 = bounding box, #2 = first sphere, #3 = second sphere"
% ——————————-
% 4) Create femodel for magnetostatics
% ——————————-
model = femodel(AnalysisType="magnetostatic", Geometry=gm);
% Specify vacuum permeability in SI (H/m)
model.VacuumPermeability = 4*pi*1e-7; % ~ 1.2566370614e-6
% ——————————-
% 5) Set material properties
% ——————————-
% We have 3 cells:
% 1 => bounding box (air)
% 2 => sphere #1
% 3 => sphere #2
%
% For air and the spheres, assume relative permeability ~ 1
model.MaterialProperties(1) = materialProperties(RelativePermeability=1);
model.MaterialProperties(2) = materialProperties(RelativePermeability=1);
model.MaterialProperties(3) = materialProperties(RelativePermeability=1);
% ——————————-
% 6) Assign magnetization
% ——————————-
% In new PDE Toolbox, you can set magnetization on the "CellLoad" for a subdomain (cell).
% Suppose sphere #1 is magnetized in +z; sphere #2 in -z.
% For a typical neodymium magnet, you might set M ~ 1e5 or 1e6 A/m.
M1 = [0; 0; 1e5];
M2 = [0; 0;-1e5];
model.CellLoad(2) = cellLoad(Magnetization=M1); % sphere1
model.CellLoad(3) = cellLoad(Magnetization=M2); % sphere2
% ——————————-
% 7) Boundary conditions
% ——————————-
% Typically, you’d set a "zero" magnetic potential (A = 0) on the outer faces
% of the bounding box to approximate an open boundary.
% Identify the face IDs of the bounding box:
% pdegplot(gm, FaceAlpha=0.1, CellLabels="on", FaceLabels="on")
% The bounding box typically has 6 faces with IDs [1..6].
% So we do:
model.FaceBC(1:6) = faceBC(MagneticPotential=[0;0;0]);
% (If you find different face numbering, adjust accordingly.)
% ——————————-
% 8) Generate mesh
% ——————————-
% We can specify "Hcell" to refine the mesh in certain cells, e.g. the magnets,
% or keep it uniform. For example, refine in cells 2 & 3 (the spheres):
internalCells = [2 3];
model = generateMesh(model, Hcell={internalCells, R_sphere/3});
% ——————————-
% 9) Solve
% ——————————-
R = solve(model);
% R is a MagnetostaticResults object with fields:
% R.MagneticPotential, R.MagneticField, R.MagneticFluxDensity, R.Mesh, etc.
% ——————————-
% 10) Postprocessing
% ——————————-
% Extract Bx, By, Bz at the mesh nodes
Bx = R.MagneticFluxDensity.Bx;
By = R.MagneticFluxDensity.By;
Bz = R.MagneticFluxDensity.Bz;
Bmag = sqrt(Bx.^2 + By.^2 + Bz.^2);
% Simple 3D plot of |B|
figure;
pdeplot3D(R.Mesh, ColorMapData=Bmag);
title("|B| flux density magnitude");
colorbar;
% Optionally, a vector plot:
figure;
pdeplot3D(R.Mesh, FlowData=[Bx By Bz]);
title("Magnetic Field Vectors");
end
While logically complete, the above code doesn’t work. The current error I am struggling with is that addCell() only works inside the original geometry. And throws the following error here:
Error using pde.DiscreteGeometry/addCell
Added cells must be located strictly inside a single cell of the original geometry.
Error in
TwoMagnets (line 38)
gm = addCell(boxGm, sphere1Gm);
^^^^^^^^^^^^^^^^^^^^^^^^^
Is there an example script on how to simulate permanent magnets using the latest PDE Toolbox?I am trying to model and visualize two permanent magnet spheres using the below code snippet:
function twoMagnets_femodel_demo()
clc; clear; close all;
% ——————————-
% 1) Define geometry parameters
% ——————————-
% Let’s assume "1/2-inch magnets" => diameter = 0.5 inch => radius = 0.25 in
% 1 inch ~ 0.0254 m, so 0.25 in ~ 0.00635 m
R_sphere = 0.00635; % [m]
% Bounding box of ~5 cm each side
boxDim = 0.05; % [m]
% ——————————-
% 2) Build geometry parts
% ——————————-
% (a) Air region: bounding box
boxGm = multicuboid(boxDim, boxDim, boxDim);
% (b) Sphere #1
sphere1Gm = multisphere(R_sphere);
% (c) Sphere #2
sphere2Gm = multisphere(R_sphere);
% Translate spheres so that they’re centered in the box, side-by-side
% Let the box corners go from (0,0,0) to (0.05,0.05,0.05), so center ~ (0.025,0.025,0.025)
centerBox = [0.025, 0.025, 0.025];
offset1 = centerBox + [-R_sphere, 0, 0]; % shift left in x
offset2 = centerBox + [ R_sphere, 0, 0]; % shift right in x
sphere1Gm = translate(sphere1Gm, offset1);
sphere2Gm = translate(sphere2Gm, offset2);
% ——————————-
% 3) Combine geometries
% ——————————-
% addCell(…) is the new PDE Toolbox function that
% keeps each shape as a separate "cell" in the final geometry.
gm = addCell(boxGm, sphere1Gm);
gm = addCell(gm, sphere2Gm);
% Visualize & label
figure;
pdegplot(gm, FaceAlpha=0.2, CellLabels="on");
title("Bounding Box + Two Spheres");
axis equal
% At this point we should see "Cell #1 = bounding box, #2 = first sphere, #3 = second sphere"
% ——————————-
% 4) Create femodel for magnetostatics
% ——————————-
model = femodel(AnalysisType="magnetostatic", Geometry=gm);
% Specify vacuum permeability in SI (H/m)
model.VacuumPermeability = 4*pi*1e-7; % ~ 1.2566370614e-6
% ——————————-
% 5) Set material properties
% ——————————-
% We have 3 cells:
% 1 => bounding box (air)
% 2 => sphere #1
% 3 => sphere #2
%
% For air and the spheres, assume relative permeability ~ 1
model.MaterialProperties(1) = materialProperties(RelativePermeability=1);
model.MaterialProperties(2) = materialProperties(RelativePermeability=1);
model.MaterialProperties(3) = materialProperties(RelativePermeability=1);
% ——————————-
% 6) Assign magnetization
% ——————————-
% In new PDE Toolbox, you can set magnetization on the "CellLoad" for a subdomain (cell).
% Suppose sphere #1 is magnetized in +z; sphere #2 in -z.
% For a typical neodymium magnet, you might set M ~ 1e5 or 1e6 A/m.
M1 = [0; 0; 1e5];
M2 = [0; 0;-1e5];
model.CellLoad(2) = cellLoad(Magnetization=M1); % sphere1
model.CellLoad(3) = cellLoad(Magnetization=M2); % sphere2
% ——————————-
% 7) Boundary conditions
% ——————————-
% Typically, you’d set a "zero" magnetic potential (A = 0) on the outer faces
% of the bounding box to approximate an open boundary.
% Identify the face IDs of the bounding box:
% pdegplot(gm, FaceAlpha=0.1, CellLabels="on", FaceLabels="on")
% The bounding box typically has 6 faces with IDs [1..6].
% So we do:
model.FaceBC(1:6) = faceBC(MagneticPotential=[0;0;0]);
% (If you find different face numbering, adjust accordingly.)
% ——————————-
% 8) Generate mesh
% ——————————-
% We can specify "Hcell" to refine the mesh in certain cells, e.g. the magnets,
% or keep it uniform. For example, refine in cells 2 & 3 (the spheres):
internalCells = [2 3];
model = generateMesh(model, Hcell={internalCells, R_sphere/3});
% ——————————-
% 9) Solve
% ——————————-
R = solve(model);
% R is a MagnetostaticResults object with fields:
% R.MagneticPotential, R.MagneticField, R.MagneticFluxDensity, R.Mesh, etc.
% ——————————-
% 10) Postprocessing
% ——————————-
% Extract Bx, By, Bz at the mesh nodes
Bx = R.MagneticFluxDensity.Bx;
By = R.MagneticFluxDensity.By;
Bz = R.MagneticFluxDensity.Bz;
Bmag = sqrt(Bx.^2 + By.^2 + Bz.^2);
% Simple 3D plot of |B|
figure;
pdeplot3D(R.Mesh, ColorMapData=Bmag);
title("|B| flux density magnitude");
colorbar;
% Optionally, a vector plot:
figure;
pdeplot3D(R.Mesh, FlowData=[Bx By Bz]);
title("Magnetic Field Vectors");
end
While logically complete, the above code doesn’t work. The current error I am struggling with is that addCell() only works inside the original geometry. And throws the following error here:
Error using pde.DiscreteGeometry/addCell
Added cells must be located strictly inside a single cell of the original geometry.
Error in
TwoMagnets (line 38)
gm = addCell(boxGm, sphere1Gm);
^^^^^^^^^^^^^^^^^^^^^^^^^
Is there an example script on how to simulate permanent magnets using the latest PDE Toolbox? I am trying to model and visualize two permanent magnet spheres using the below code snippet:
function twoMagnets_femodel_demo()
clc; clear; close all;
% ——————————-
% 1) Define geometry parameters
% ——————————-
% Let’s assume "1/2-inch magnets" => diameter = 0.5 inch => radius = 0.25 in
% 1 inch ~ 0.0254 m, so 0.25 in ~ 0.00635 m
R_sphere = 0.00635; % [m]
% Bounding box of ~5 cm each side
boxDim = 0.05; % [m]
% ——————————-
% 2) Build geometry parts
% ——————————-
% (a) Air region: bounding box
boxGm = multicuboid(boxDim, boxDim, boxDim);
% (b) Sphere #1
sphere1Gm = multisphere(R_sphere);
% (c) Sphere #2
sphere2Gm = multisphere(R_sphere);
% Translate spheres so that they’re centered in the box, side-by-side
% Let the box corners go from (0,0,0) to (0.05,0.05,0.05), so center ~ (0.025,0.025,0.025)
centerBox = [0.025, 0.025, 0.025];
offset1 = centerBox + [-R_sphere, 0, 0]; % shift left in x
offset2 = centerBox + [ R_sphere, 0, 0]; % shift right in x
sphere1Gm = translate(sphere1Gm, offset1);
sphere2Gm = translate(sphere2Gm, offset2);
% ——————————-
% 3) Combine geometries
% ——————————-
% addCell(…) is the new PDE Toolbox function that
% keeps each shape as a separate "cell" in the final geometry.
gm = addCell(boxGm, sphere1Gm);
gm = addCell(gm, sphere2Gm);
% Visualize & label
figure;
pdegplot(gm, FaceAlpha=0.2, CellLabels="on");
title("Bounding Box + Two Spheres");
axis equal
% At this point we should see "Cell #1 = bounding box, #2 = first sphere, #3 = second sphere"
% ——————————-
% 4) Create femodel for magnetostatics
% ——————————-
model = femodel(AnalysisType="magnetostatic", Geometry=gm);
% Specify vacuum permeability in SI (H/m)
model.VacuumPermeability = 4*pi*1e-7; % ~ 1.2566370614e-6
% ——————————-
% 5) Set material properties
% ——————————-
% We have 3 cells:
% 1 => bounding box (air)
% 2 => sphere #1
% 3 => sphere #2
%
% For air and the spheres, assume relative permeability ~ 1
model.MaterialProperties(1) = materialProperties(RelativePermeability=1);
model.MaterialProperties(2) = materialProperties(RelativePermeability=1);
model.MaterialProperties(3) = materialProperties(RelativePermeability=1);
% ——————————-
% 6) Assign magnetization
% ——————————-
% In new PDE Toolbox, you can set magnetization on the "CellLoad" for a subdomain (cell).
% Suppose sphere #1 is magnetized in +z; sphere #2 in -z.
% For a typical neodymium magnet, you might set M ~ 1e5 or 1e6 A/m.
M1 = [0; 0; 1e5];
M2 = [0; 0;-1e5];
model.CellLoad(2) = cellLoad(Magnetization=M1); % sphere1
model.CellLoad(3) = cellLoad(Magnetization=M2); % sphere2
% ——————————-
% 7) Boundary conditions
% ——————————-
% Typically, you’d set a "zero" magnetic potential (A = 0) on the outer faces
% of the bounding box to approximate an open boundary.
% Identify the face IDs of the bounding box:
% pdegplot(gm, FaceAlpha=0.1, CellLabels="on", FaceLabels="on")
% The bounding box typically has 6 faces with IDs [1..6].
% So we do:
model.FaceBC(1:6) = faceBC(MagneticPotential=[0;0;0]);
% (If you find different face numbering, adjust accordingly.)
% ——————————-
% 8) Generate mesh
% ——————————-
% We can specify "Hcell" to refine the mesh in certain cells, e.g. the magnets,
% or keep it uniform. For example, refine in cells 2 & 3 (the spheres):
internalCells = [2 3];
model = generateMesh(model, Hcell={internalCells, R_sphere/3});
% ——————————-
% 9) Solve
% ——————————-
R = solve(model);
% R is a MagnetostaticResults object with fields:
% R.MagneticPotential, R.MagneticField, R.MagneticFluxDensity, R.Mesh, etc.
% ——————————-
% 10) Postprocessing
% ——————————-
% Extract Bx, By, Bz at the mesh nodes
Bx = R.MagneticFluxDensity.Bx;
By = R.MagneticFluxDensity.By;
Bz = R.MagneticFluxDensity.Bz;
Bmag = sqrt(Bx.^2 + By.^2 + Bz.^2);
% Simple 3D plot of |B|
figure;
pdeplot3D(R.Mesh, ColorMapData=Bmag);
title("|B| flux density magnitude");
colorbar;
% Optionally, a vector plot:
figure;
pdeplot3D(R.Mesh, FlowData=[Bx By Bz]);
title("Magnetic Field Vectors");
end
While logically complete, the above code doesn’t work. The current error I am struggling with is that addCell() only works inside the original geometry. And throws the following error here:
Error using pde.DiscreteGeometry/addCell
Added cells must be located strictly inside a single cell of the original geometry.
Error in
TwoMagnets (line 38)
gm = addCell(boxGm, sphere1Gm);
^^^^^^^^^^^^^^^^^^^^^^^^^
Is there an example script on how to simulate permanent magnets using the latest PDE Toolbox? pde, matlab code, mesh MATLAB Answers — New Questions
How can I plot multiple figures in one from multiple saved .fig files that have 2 figures but I only want 1 of them?
I have run multiple simulations of a system and in each run I changed one parameter. I saved the .fig files of a scope I am interested in but the scope plots 2 figures separated by the layout function (so there is one on top and one on the bottom part when you click/view the scope). How can I plot only the top figure (1st input in the scope) from the various .fig files that I saved? I want to highlight the difference when I change a specific parameter (increase and decrease) and repeat for each parameter that I changed.
Thank you a lot in advance!I have run multiple simulations of a system and in each run I changed one parameter. I saved the .fig files of a scope I am interested in but the scope plots 2 figures separated by the layout function (so there is one on top and one on the bottom part when you click/view the scope). How can I plot only the top figure (1st input in the scope) from the various .fig files that I saved? I want to highlight the difference when I change a specific parameter (increase and decrease) and repeat for each parameter that I changed.
Thank you a lot in advance! I have run multiple simulations of a system and in each run I changed one parameter. I saved the .fig files of a scope I am interested in but the scope plots 2 figures separated by the layout function (so there is one on top and one on the bottom part when you click/view the scope). How can I plot only the top figure (1st input in the scope) from the various .fig files that I saved? I want to highlight the difference when I change a specific parameter (increase and decrease) and repeat for each parameter that I changed.
Thank you a lot in advance! matlab, simulink, figure MATLAB Answers — New Questions
Characterize RC parameters of a battery cell.
Hi,
I want to extract RC values from HPPC test, and I found a good example on MathWorks:Characterize Battery Cell for Electric Vehicles, However I can find batt_BatteryCellCharacterization function, is there anything I need to do?Hi,
I want to extract RC values from HPPC test, and I found a good example on MathWorks:Characterize Battery Cell for Electric Vehicles, However I can find batt_BatteryCellCharacterization function, is there anything I need to do? Hi,
I want to extract RC values from HPPC test, and I found a good example on MathWorks:Characterize Battery Cell for Electric Vehicles, However I can find batt_BatteryCellCharacterization function, is there anything I need to do? battery, modelling MATLAB Answers — New Questions
multiplicationLayer – multiply by a constant
I’m trying to implement a neural net in which a layer multiplies every input by a constant. There is a multiplicationLayer net in the Deep Learning Toolbox which can have any number of inputs, but I cannot connect one of those inputs to a constant of any type.
TIA!I’m trying to implement a neural net in which a layer multiplies every input by a constant. There is a multiplicationLayer net in the Deep Learning Toolbox which can have any number of inputs, but I cannot connect one of those inputs to a constant of any type.
TIA! I’m trying to implement a neural net in which a layer multiplies every input by a constant. There is a multiplicationLayer net in the Deep Learning Toolbox which can have any number of inputs, but I cannot connect one of those inputs to a constant of any type.
TIA! multiplicationlayer MATLAB Answers — New Questions
Running/testing scripts on multiple Matlab/Simulink versions?
I do a lot of script and tool development for Matlab/Simulink. This involves supporting multiple versions of Matlab, usually from R2016a+ (previously it was R2011b+). This means that I have almost a dozen different versions of Matlab installed on my computer. When one of my tools/scripts encounters a bug in a version of Matlab, or the Matlab/Simulink behaviour differs between versions, I need to be able to pinpoint which version the bug occurred in or the behaviour changed in. I usually can’t find the bugs listed on the Bug Reports support page, especially when the bugs are already fixed in later versions. Likewise, when the behaviour changes I check if it is noted in the Release Notes, but these are very high-level descriptions and I usually can’t find it mentioned.
Given that the aforementioned pages are not reliable, I usually need to figure out which version of Matlab has the bug fix or behaviour change. I typically follow this process:
I create a script to replicate the bug automatically (if possible).
One by one I open each version of Matlab, execute the script, and make note of when the bug occurs. Sometimes I have to download and install additional Matlab versions.
Then I develop a workaround for the bug or behaviour change by having the script check which version it is running on, and then perform extra steps to fix the buggy behavior or accommodate for inconsistent behaviours between the versions.
My questions is: Is it possible run a script on multiple versions of Matlab in order to make this process a little easier?I do a lot of script and tool development for Matlab/Simulink. This involves supporting multiple versions of Matlab, usually from R2016a+ (previously it was R2011b+). This means that I have almost a dozen different versions of Matlab installed on my computer. When one of my tools/scripts encounters a bug in a version of Matlab, or the Matlab/Simulink behaviour differs between versions, I need to be able to pinpoint which version the bug occurred in or the behaviour changed in. I usually can’t find the bugs listed on the Bug Reports support page, especially when the bugs are already fixed in later versions. Likewise, when the behaviour changes I check if it is noted in the Release Notes, but these are very high-level descriptions and I usually can’t find it mentioned.
Given that the aforementioned pages are not reliable, I usually need to figure out which version of Matlab has the bug fix or behaviour change. I typically follow this process:
I create a script to replicate the bug automatically (if possible).
One by one I open each version of Matlab, execute the script, and make note of when the bug occurs. Sometimes I have to download and install additional Matlab versions.
Then I develop a workaround for the bug or behaviour change by having the script check which version it is running on, and then perform extra steps to fix the buggy behavior or accommodate for inconsistent behaviours between the versions.
My questions is: Is it possible run a script on multiple versions of Matlab in order to make this process a little easier? I do a lot of script and tool development for Matlab/Simulink. This involves supporting multiple versions of Matlab, usually from R2016a+ (previously it was R2011b+). This means that I have almost a dozen different versions of Matlab installed on my computer. When one of my tools/scripts encounters a bug in a version of Matlab, or the Matlab/Simulink behaviour differs between versions, I need to be able to pinpoint which version the bug occurred in or the behaviour changed in. I usually can’t find the bugs listed on the Bug Reports support page, especially when the bugs are already fixed in later versions. Likewise, when the behaviour changes I check if it is noted in the Release Notes, but these are very high-level descriptions and I usually can’t find it mentioned.
Given that the aforementioned pages are not reliable, I usually need to figure out which version of Matlab has the bug fix or behaviour change. I typically follow this process:
I create a script to replicate the bug automatically (if possible).
One by one I open each version of Matlab, execute the script, and make note of when the bug occurs. Sometimes I have to download and install additional Matlab versions.
Then I develop a workaround for the bug or behaviour change by having the script check which version it is running on, and then perform extra steps to fix the buggy behavior or accommodate for inconsistent behaviours between the versions.
My questions is: Is it possible run a script on multiple versions of Matlab in order to make this process a little easier? version, bugs, release notes, bug reports MATLAB Answers — New Questions
Concatenation Error when using LSTM Layers in a Hybrid Actor (RL Toolbox)
Hey,
Unfortunately, I run into a concatenation error when I try to use LSTM layers combined with a hybrid actor in my RL framework. There would be an easy way to fix that in the sequenceExperienceArray.m file from the RL toolbox, however, I cannot save the changes because I get the error "Access denied".
Did anyone else experience this and found a workaround?
Thanks!Hey,
Unfortunately, I run into a concatenation error when I try to use LSTM layers combined with a hybrid actor in my RL framework. There would be an easy way to fix that in the sequenceExperienceArray.m file from the RL toolbox, however, I cannot save the changes because I get the error "Access denied".
Did anyone else experience this and found a workaround?
Thanks! Hey,
Unfortunately, I run into a concatenation error when I try to use LSTM layers combined with a hybrid actor in my RL framework. There would be an easy way to fix that in the sequenceExperienceArray.m file from the RL toolbox, however, I cannot save the changes because I get the error "Access denied".
Did anyone else experience this and found a workaround?
Thanks! rl-toolbox, lstm, concatenation MATLAB Answers — New Questions
Problem while running setup of Raspberry Pi Support Package
Hi Matlabers,
I am trying to install the Rapbian imager for matlab, and while configuring my hardware in the process, i get the following error:
"cannot retrieve removable drives: ‘wmic’ is not recognized as an internal or external command, operable program or batch file"
I saw a question like this here before but the solution there wasn’t good for me.
I added the following to my Path
%SystemRoot%System32Wbem
but no good.
Please help!Hi Matlabers,
I am trying to install the Rapbian imager for matlab, and while configuring my hardware in the process, i get the following error:
"cannot retrieve removable drives: ‘wmic’ is not recognized as an internal or external command, operable program or batch file"
I saw a question like this here before but the solution there wasn’t good for me.
I added the following to my Path
%SystemRoot%System32Wbem
but no good.
Please help! Hi Matlabers,
I am trying to install the Rapbian imager for matlab, and while configuring my hardware in the process, i get the following error:
"cannot retrieve removable drives: ‘wmic’ is not recognized as an internal or external command, operable program or batch file"
I saw a question like this here before but the solution there wasn’t good for me.
I added the following to my Path
%SystemRoot%System32Wbem
but no good.
Please help! raspberry pi, system, path, packages, installation MATLAB Answers — New Questions
Update the content of a MatLab generated executable
I would like to update the content of an executable inside a generated executable MatLab file. The file is generated with MatLab/Simulink compiler. Why would I want to do this? Because I need to sign the content of all executable that run on my company pc. I know I can open the generated executable as a zip file. Inside I can update or add any file.
I have found that there is a sig1.xml file that contains the sha512 encoded with base64. So I have updated the sha512 signature of the modified file. But I have an error when opening the executable: CTF archive is invalid
Is there a global signature to update? Or anything else?
Any advice is welcome!I would like to update the content of an executable inside a generated executable MatLab file. The file is generated with MatLab/Simulink compiler. Why would I want to do this? Because I need to sign the content of all executable that run on my company pc. I know I can open the generated executable as a zip file. Inside I can update or add any file.
I have found that there is a sig1.xml file that contains the sha512 encoded with base64. So I have updated the sha512 signature of the modified file. But I have an error when opening the executable: CTF archive is invalid
Is there a global signature to update? Or anything else?
Any advice is welcome! I would like to update the content of an executable inside a generated executable MatLab file. The file is generated with MatLab/Simulink compiler. Why would I want to do this? Because I need to sign the content of all executable that run on my company pc. I know I can open the generated executable as a zip file. Inside I can update or add any file.
I have found that there is a sig1.xml file that contains the sha512 encoded with base64. So I have updated the sha512 signature of the modified file. But I have an error when opening the executable: CTF archive is invalid
Is there a global signature to update? Or anything else?
Any advice is welcome! matlab MATLAB Answers — New Questions
How to solve system of PDE’s using crank nicolson method to get graphical interpretations of equations? How to get skin friction and nusselt number using this code?
i have attached my matlb code for solving system of PDE ∂u/∂t=(∂^2 u)/〖∂η〗^2 +α (∂^3 u)/〖∂η〗^3 +δcφ+Grθ-Mu
∂θ/∂t=1/Pr (∂^2 θ)/〖∂η〗^2 +D_f (∂^2 φ)/〖∂η〗^2
∂φ/∂t=1/S_c (∂^2 φ)/〖∂η〗^2 +S_r (∂^2 θ)/〖∂η〗^2
when η→0
when η→0:u=sin(wt),θ=1 ,φ=1
when η→∞:u→0,θ→0,φ→0
But,i’m confused how to set boundary conditions in this code. Also i want to set these skin friction and nusselt number expressions: C_f=-(∂u/∂η) at η=0
Nu〖Re〗_x^(-1)=-(∂θ/∂η) at η=0
in this code;
function yy= crank
n=105;
h=0.01;
m=0.1;
B=0; %B=0.0001;
Gr=2; %Gr=0.1=Delt. Gs=Dels
A=2; %A=alpha
Pr=5;
Gs=1; %3.5
Sc=1.5;
M=9; %M=30,12
Df=5;
Sr=10;
Ec=0.1; % 0.01-0.1(0-1)
t(1)=0;
s(1)=0;
for j=2:n
t(j)=t(j-1)+h;
end
for j=2:n
s(j)=s(j-1)+m;
end
k=1;
for j=1:n
aa(j,k)=exp(-0.15*Pr^2*t(j)*Ec^-0.1/Gr^0.1); % Guess M*Gr*Gs*S
bb(j,k)=exp(-t(j)*Sc/(Ec)^0.01*M); %bb(j,k)=exp(-Pr^2*t(j)/Ec);
cc(j,k)=exp(-Sc*2*t(j)/Ec^0.3);
end
a{1,k}=[1 0 0;0 1 0;0 0 1];
for j=2:n-1
a{j,k}=[-(1/h)-(1/h^2)-2*A-M Gr Gs;0 -(1/h)-(1/Pr*(h^2)) -Df/h^2;0 -Sr/h^2 -(1/h)-(1/Sc*h^2)];
end
a{n,k}=[1 0 0;0 1 0;0 0 1];
for j=2:n-1
b{j,k}=[(1/2*h^2)+(A/h^3) 0 0;0 1/2*Pr*h^2 Df/2*h^2;0 Sr/2*h^2 1/2*Sc*h^2]; % Lower diagonal entries
end
b{n,k}=[0 0 0;0 0 0;0 0 0];
c{1,k}=[0 0 0;0 0 0;0 0 0];
for j=2:n-1
c{j,k}=[(1/2*h^2)+(A/h^3) 0 0;0 1/2*Pr*h^2 Df/2*h^2;0 Sr/2*h^2 1/2*Sc*h^2];
end
r1(1,k)=0;
r2(1,k)=0;
r3(1,k)=0;
for j=2:n-1
r1(j,k)=-(exp(t(j))/h)-(1/2*h^2)*(1)*(exp(-t(j+1))-2*exp(-t(j))+exp(-t(j-1)))-Gr*exp(-t(j))-Gs*exp(t(j))+M*exp(-t(j))-(A/2*h^3)*(-exp(-t(j+1))+2*exp(-t(j))-exp(-t(j-1)))…
+(aa(j,k)/h)-(1/2*h^2)*(1)*(aa(j+1,k)-2*aa(j,k)+aa(j-1,k))-(A/2*h^3)*( aa(j+1,k)^2-2*aa(j+1,k)*aa(j,k))-Gr*bb(j,k)-Gs*cc(j,k)+M*aa(j,k);
r2(j,k)=(exp((-t(j)))/h)-(1/2*Pr*h^2)*(exp(-t(j+1))-2* exp(-t(j))+exp(-t(j-1)))-Df*(1/2*h^2)*(exp(-t(j+1))-2* exp(-t(j))…
+exp(-t(j-1)))+(bb(j,k)/h)-(1/2*Pr*h^2)*(bb(j+1,k)-2*bb(j,k)+bb(j-1,k))-(Df/2*h^2)*(cc(j+1,k)-2*cc(j,k)+cc(j-1,k));
r3(j,k)=-(exp((-t(j)))/h)-(1/2*Sc*h^2)*(exp(-t(j+1))-2*exp(-t(j))+exp(-t(j-1)))-(Sr/2*h^2)*(exp(-t(j+1))-2*exp(-t(j))+exp(-t(j-1)))+ (cc(j,k)/h)…
-(1/2*Sc*h^2)*(cc(j+1,k)-2*cc(j,k)+cc(j-1,k))-(Sr/2*h^2)*(bb(j+1,k)-2*bb(j,k)+bb(j-1,k));
end
r1(n,k)= 0;
r2(n,k)=0;
r3(n,k)=0;
for j=1:n
rr{j,k}=[r1(j,k);r2(j,k);r3(j,k)];
end
gamma{1,k}=inv(a{1,k})*c{1,k};
for j=2:n-1
a{j,k}=a{j,k}-(b{j,k}*gamma{j-1,k});
gamma{j,k}=inv(a{j,k})*c{j,k};
end
y{1}=inv(a{1})*rr{1};
for j=2:n
y{j}=inv(a{j})*(rr{j}-b{j}*y{j-1});
end
x{n}=y{n};
for j=n-1:-1:1
x{j}=y{j}-(gamma{j})*x{j+1};
end
for j=n:-1:1
u(j,k)=x{j}(1,1);
z(j,k)=x{j}(2,1);
q(j,k)=x{j}(3,1);
end
for j=1:n
xx(j,k)= aa(j,k)+u(j,k);
yy(j,k)= bb(j,k)+z(j,k);
zz(j,k)= cc(j,k)+q(j,k);
end
for j=1:n-1
%U(j)=-((1+(1/B))*((xx(j+1)-xx(j))/h))
%U(j)=-((yy(j+1)-yy(j))/2*h)
end
%ee=meshgrid(xx);
%V=trapz(ee);
%eee=meshgrid(V);
%[XX,YY]=meshgrid(t,s);
%XXX=meshgrid(xx);
%surf(XX,YY,XXX)
%contour(eee)
figure(1)
plot(t,xx,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’-‘,’color’,’k’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘u’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold on
figure(2)
plot(t,yy,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’-‘,’color’,’k’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘Theta(eta)’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold on
figure(3)
plot(t,zz,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’–‘,’color’,’r’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘Phi(eta)’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold oni have attached my matlb code for solving system of PDE ∂u/∂t=(∂^2 u)/〖∂η〗^2 +α (∂^3 u)/〖∂η〗^3 +δcφ+Grθ-Mu
∂θ/∂t=1/Pr (∂^2 θ)/〖∂η〗^2 +D_f (∂^2 φ)/〖∂η〗^2
∂φ/∂t=1/S_c (∂^2 φ)/〖∂η〗^2 +S_r (∂^2 θ)/〖∂η〗^2
when η→0
when η→0:u=sin(wt),θ=1 ,φ=1
when η→∞:u→0,θ→0,φ→0
But,i’m confused how to set boundary conditions in this code. Also i want to set these skin friction and nusselt number expressions: C_f=-(∂u/∂η) at η=0
Nu〖Re〗_x^(-1)=-(∂θ/∂η) at η=0
in this code;
function yy= crank
n=105;
h=0.01;
m=0.1;
B=0; %B=0.0001;
Gr=2; %Gr=0.1=Delt. Gs=Dels
A=2; %A=alpha
Pr=5;
Gs=1; %3.5
Sc=1.5;
M=9; %M=30,12
Df=5;
Sr=10;
Ec=0.1; % 0.01-0.1(0-1)
t(1)=0;
s(1)=0;
for j=2:n
t(j)=t(j-1)+h;
end
for j=2:n
s(j)=s(j-1)+m;
end
k=1;
for j=1:n
aa(j,k)=exp(-0.15*Pr^2*t(j)*Ec^-0.1/Gr^0.1); % Guess M*Gr*Gs*S
bb(j,k)=exp(-t(j)*Sc/(Ec)^0.01*M); %bb(j,k)=exp(-Pr^2*t(j)/Ec);
cc(j,k)=exp(-Sc*2*t(j)/Ec^0.3);
end
a{1,k}=[1 0 0;0 1 0;0 0 1];
for j=2:n-1
a{j,k}=[-(1/h)-(1/h^2)-2*A-M Gr Gs;0 -(1/h)-(1/Pr*(h^2)) -Df/h^2;0 -Sr/h^2 -(1/h)-(1/Sc*h^2)];
end
a{n,k}=[1 0 0;0 1 0;0 0 1];
for j=2:n-1
b{j,k}=[(1/2*h^2)+(A/h^3) 0 0;0 1/2*Pr*h^2 Df/2*h^2;0 Sr/2*h^2 1/2*Sc*h^2]; % Lower diagonal entries
end
b{n,k}=[0 0 0;0 0 0;0 0 0];
c{1,k}=[0 0 0;0 0 0;0 0 0];
for j=2:n-1
c{j,k}=[(1/2*h^2)+(A/h^3) 0 0;0 1/2*Pr*h^2 Df/2*h^2;0 Sr/2*h^2 1/2*Sc*h^2];
end
r1(1,k)=0;
r2(1,k)=0;
r3(1,k)=0;
for j=2:n-1
r1(j,k)=-(exp(t(j))/h)-(1/2*h^2)*(1)*(exp(-t(j+1))-2*exp(-t(j))+exp(-t(j-1)))-Gr*exp(-t(j))-Gs*exp(t(j))+M*exp(-t(j))-(A/2*h^3)*(-exp(-t(j+1))+2*exp(-t(j))-exp(-t(j-1)))…
+(aa(j,k)/h)-(1/2*h^2)*(1)*(aa(j+1,k)-2*aa(j,k)+aa(j-1,k))-(A/2*h^3)*( aa(j+1,k)^2-2*aa(j+1,k)*aa(j,k))-Gr*bb(j,k)-Gs*cc(j,k)+M*aa(j,k);
r2(j,k)=(exp((-t(j)))/h)-(1/2*Pr*h^2)*(exp(-t(j+1))-2* exp(-t(j))+exp(-t(j-1)))-Df*(1/2*h^2)*(exp(-t(j+1))-2* exp(-t(j))…
+exp(-t(j-1)))+(bb(j,k)/h)-(1/2*Pr*h^2)*(bb(j+1,k)-2*bb(j,k)+bb(j-1,k))-(Df/2*h^2)*(cc(j+1,k)-2*cc(j,k)+cc(j-1,k));
r3(j,k)=-(exp((-t(j)))/h)-(1/2*Sc*h^2)*(exp(-t(j+1))-2*exp(-t(j))+exp(-t(j-1)))-(Sr/2*h^2)*(exp(-t(j+1))-2*exp(-t(j))+exp(-t(j-1)))+ (cc(j,k)/h)…
-(1/2*Sc*h^2)*(cc(j+1,k)-2*cc(j,k)+cc(j-1,k))-(Sr/2*h^2)*(bb(j+1,k)-2*bb(j,k)+bb(j-1,k));
end
r1(n,k)= 0;
r2(n,k)=0;
r3(n,k)=0;
for j=1:n
rr{j,k}=[r1(j,k);r2(j,k);r3(j,k)];
end
gamma{1,k}=inv(a{1,k})*c{1,k};
for j=2:n-1
a{j,k}=a{j,k}-(b{j,k}*gamma{j-1,k});
gamma{j,k}=inv(a{j,k})*c{j,k};
end
y{1}=inv(a{1})*rr{1};
for j=2:n
y{j}=inv(a{j})*(rr{j}-b{j}*y{j-1});
end
x{n}=y{n};
for j=n-1:-1:1
x{j}=y{j}-(gamma{j})*x{j+1};
end
for j=n:-1:1
u(j,k)=x{j}(1,1);
z(j,k)=x{j}(2,1);
q(j,k)=x{j}(3,1);
end
for j=1:n
xx(j,k)= aa(j,k)+u(j,k);
yy(j,k)= bb(j,k)+z(j,k);
zz(j,k)= cc(j,k)+q(j,k);
end
for j=1:n-1
%U(j)=-((1+(1/B))*((xx(j+1)-xx(j))/h))
%U(j)=-((yy(j+1)-yy(j))/2*h)
end
%ee=meshgrid(xx);
%V=trapz(ee);
%eee=meshgrid(V);
%[XX,YY]=meshgrid(t,s);
%XXX=meshgrid(xx);
%surf(XX,YY,XXX)
%contour(eee)
figure(1)
plot(t,xx,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’-‘,’color’,’k’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘u’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold on
figure(2)
plot(t,yy,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’-‘,’color’,’k’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘Theta(eta)’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold on
figure(3)
plot(t,zz,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’–‘,’color’,’r’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘Phi(eta)’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold on i have attached my matlb code for solving system of PDE ∂u/∂t=(∂^2 u)/〖∂η〗^2 +α (∂^3 u)/〖∂η〗^3 +δcφ+Grθ-Mu
∂θ/∂t=1/Pr (∂^2 θ)/〖∂η〗^2 +D_f (∂^2 φ)/〖∂η〗^2
∂φ/∂t=1/S_c (∂^2 φ)/〖∂η〗^2 +S_r (∂^2 θ)/〖∂η〗^2
when η→0
when η→0:u=sin(wt),θ=1 ,φ=1
when η→∞:u→0,θ→0,φ→0
But,i’m confused how to set boundary conditions in this code. Also i want to set these skin friction and nusselt number expressions: C_f=-(∂u/∂η) at η=0
Nu〖Re〗_x^(-1)=-(∂θ/∂η) at η=0
in this code;
function yy= crank
n=105;
h=0.01;
m=0.1;
B=0; %B=0.0001;
Gr=2; %Gr=0.1=Delt. Gs=Dels
A=2; %A=alpha
Pr=5;
Gs=1; %3.5
Sc=1.5;
M=9; %M=30,12
Df=5;
Sr=10;
Ec=0.1; % 0.01-0.1(0-1)
t(1)=0;
s(1)=0;
for j=2:n
t(j)=t(j-1)+h;
end
for j=2:n
s(j)=s(j-1)+m;
end
k=1;
for j=1:n
aa(j,k)=exp(-0.15*Pr^2*t(j)*Ec^-0.1/Gr^0.1); % Guess M*Gr*Gs*S
bb(j,k)=exp(-t(j)*Sc/(Ec)^0.01*M); %bb(j,k)=exp(-Pr^2*t(j)/Ec);
cc(j,k)=exp(-Sc*2*t(j)/Ec^0.3);
end
a{1,k}=[1 0 0;0 1 0;0 0 1];
for j=2:n-1
a{j,k}=[-(1/h)-(1/h^2)-2*A-M Gr Gs;0 -(1/h)-(1/Pr*(h^2)) -Df/h^2;0 -Sr/h^2 -(1/h)-(1/Sc*h^2)];
end
a{n,k}=[1 0 0;0 1 0;0 0 1];
for j=2:n-1
b{j,k}=[(1/2*h^2)+(A/h^3) 0 0;0 1/2*Pr*h^2 Df/2*h^2;0 Sr/2*h^2 1/2*Sc*h^2]; % Lower diagonal entries
end
b{n,k}=[0 0 0;0 0 0;0 0 0];
c{1,k}=[0 0 0;0 0 0;0 0 0];
for j=2:n-1
c{j,k}=[(1/2*h^2)+(A/h^3) 0 0;0 1/2*Pr*h^2 Df/2*h^2;0 Sr/2*h^2 1/2*Sc*h^2];
end
r1(1,k)=0;
r2(1,k)=0;
r3(1,k)=0;
for j=2:n-1
r1(j,k)=-(exp(t(j))/h)-(1/2*h^2)*(1)*(exp(-t(j+1))-2*exp(-t(j))+exp(-t(j-1)))-Gr*exp(-t(j))-Gs*exp(t(j))+M*exp(-t(j))-(A/2*h^3)*(-exp(-t(j+1))+2*exp(-t(j))-exp(-t(j-1)))…
+(aa(j,k)/h)-(1/2*h^2)*(1)*(aa(j+1,k)-2*aa(j,k)+aa(j-1,k))-(A/2*h^3)*( aa(j+1,k)^2-2*aa(j+1,k)*aa(j,k))-Gr*bb(j,k)-Gs*cc(j,k)+M*aa(j,k);
r2(j,k)=(exp((-t(j)))/h)-(1/2*Pr*h^2)*(exp(-t(j+1))-2* exp(-t(j))+exp(-t(j-1)))-Df*(1/2*h^2)*(exp(-t(j+1))-2* exp(-t(j))…
+exp(-t(j-1)))+(bb(j,k)/h)-(1/2*Pr*h^2)*(bb(j+1,k)-2*bb(j,k)+bb(j-1,k))-(Df/2*h^2)*(cc(j+1,k)-2*cc(j,k)+cc(j-1,k));
r3(j,k)=-(exp((-t(j)))/h)-(1/2*Sc*h^2)*(exp(-t(j+1))-2*exp(-t(j))+exp(-t(j-1)))-(Sr/2*h^2)*(exp(-t(j+1))-2*exp(-t(j))+exp(-t(j-1)))+ (cc(j,k)/h)…
-(1/2*Sc*h^2)*(cc(j+1,k)-2*cc(j,k)+cc(j-1,k))-(Sr/2*h^2)*(bb(j+1,k)-2*bb(j,k)+bb(j-1,k));
end
r1(n,k)= 0;
r2(n,k)=0;
r3(n,k)=0;
for j=1:n
rr{j,k}=[r1(j,k);r2(j,k);r3(j,k)];
end
gamma{1,k}=inv(a{1,k})*c{1,k};
for j=2:n-1
a{j,k}=a{j,k}-(b{j,k}*gamma{j-1,k});
gamma{j,k}=inv(a{j,k})*c{j,k};
end
y{1}=inv(a{1})*rr{1};
for j=2:n
y{j}=inv(a{j})*(rr{j}-b{j}*y{j-1});
end
x{n}=y{n};
for j=n-1:-1:1
x{j}=y{j}-(gamma{j})*x{j+1};
end
for j=n:-1:1
u(j,k)=x{j}(1,1);
z(j,k)=x{j}(2,1);
q(j,k)=x{j}(3,1);
end
for j=1:n
xx(j,k)= aa(j,k)+u(j,k);
yy(j,k)= bb(j,k)+z(j,k);
zz(j,k)= cc(j,k)+q(j,k);
end
for j=1:n-1
%U(j)=-((1+(1/B))*((xx(j+1)-xx(j))/h))
%U(j)=-((yy(j+1)-yy(j))/2*h)
end
%ee=meshgrid(xx);
%V=trapz(ee);
%eee=meshgrid(V);
%[XX,YY]=meshgrid(t,s);
%XXX=meshgrid(xx);
%surf(XX,YY,XXX)
%contour(eee)
figure(1)
plot(t,xx,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’-‘,’color’,’k’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘u’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold on
figure(2)
plot(t,yy,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’-‘,’color’,’k’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘Theta(eta)’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold on
figure(3)
plot(t,zz,’LineWidth’,2,’MarkerSize’,16,’linestyle’,’–‘,’color’,’r’)
xlabel(‘eta’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
ylabel(‘Phi(eta)’,’Interpreter’,’tex’,’FontSize’,16,’FontWeight’,’bold’);
grid on
hold on system of pde’s, crank nicloson method in matlab, skin friction and nusselt number MATLAB Answers — New Questions