Category: Matlab
Category Archives: Matlab
iterative estimation of eigenvalues and eigenvectors by the inverse power method. Your MATLAB/Octave code shouldn’t be hardcoded. ● Calculate the eigenvectors and eigenvalues
function [lambda, v] = inverse_power_method(A, tol, max_iter)
% This function uses the inverse power method to estimate the smallest
% eigenvalue and corresponding eigenvector of matrix A.
% Inputs:
% A – The input square matrix
% tol – The tolerance for convergence (e.g., 1e-6)
% max_iter – The maximum number of iterations
% Outputs:
% lambda – The estimated smallest eigenvalue
% v – The estimated corresponding eigenvector
n = size(A, 1); % Get the size of the matrix
v = rand(n, 1); % Initialize a random vector
v = v / norm(v); % Normalize the vector
% Perform the inverse power iteration
for k = 1:max_iter
w = (A v); % Solve A * w = v
v_new = w / norm(w); % Normalize the vector
% Check for convergence
if norm(v_new – v) < tol
break;
end
v = v_new; % Update the vector
end
% Calculate the corresponding eigenvalue
lambda = v’ * A * v;
% Normalize the eigenvector to have unit length
v = v / norm(v);
end
% Define the matrix A
A = [1, -3, 3;
3, -5, 3;
6, -6, 4];
% Set the tolerance and maximum number of iterations
tol = 1e-6;
max_iter = 1000;
% Call the inverse power method function
[lambda, v] = inverse_power_method(A, tol, max_iter);
% Display the results
fprintf(‘Estimated smallest eigenvalue: %.6fn’, lambda);
fprintf(‘Estimated corresponding eigenvector:n’);
disp(v);function [lambda, v] = inverse_power_method(A, tol, max_iter)
% This function uses the inverse power method to estimate the smallest
% eigenvalue and corresponding eigenvector of matrix A.
% Inputs:
% A – The input square matrix
% tol – The tolerance for convergence (e.g., 1e-6)
% max_iter – The maximum number of iterations
% Outputs:
% lambda – The estimated smallest eigenvalue
% v – The estimated corresponding eigenvector
n = size(A, 1); % Get the size of the matrix
v = rand(n, 1); % Initialize a random vector
v = v / norm(v); % Normalize the vector
% Perform the inverse power iteration
for k = 1:max_iter
w = (A v); % Solve A * w = v
v_new = w / norm(w); % Normalize the vector
% Check for convergence
if norm(v_new – v) < tol
break;
end
v = v_new; % Update the vector
end
% Calculate the corresponding eigenvalue
lambda = v’ * A * v;
% Normalize the eigenvector to have unit length
v = v / norm(v);
end
% Define the matrix A
A = [1, -3, 3;
3, -5, 3;
6, -6, 4];
% Set the tolerance and maximum number of iterations
tol = 1e-6;
max_iter = 1000;
% Call the inverse power method function
[lambda, v] = inverse_power_method(A, tol, max_iter);
% Display the results
fprintf(‘Estimated smallest eigenvalue: %.6fn’, lambda);
fprintf(‘Estimated corresponding eigenvector:n’);
disp(v); function [lambda, v] = inverse_power_method(A, tol, max_iter)
% This function uses the inverse power method to estimate the smallest
% eigenvalue and corresponding eigenvector of matrix A.
% Inputs:
% A – The input square matrix
% tol – The tolerance for convergence (e.g., 1e-6)
% max_iter – The maximum number of iterations
% Outputs:
% lambda – The estimated smallest eigenvalue
% v – The estimated corresponding eigenvector
n = size(A, 1); % Get the size of the matrix
v = rand(n, 1); % Initialize a random vector
v = v / norm(v); % Normalize the vector
% Perform the inverse power iteration
for k = 1:max_iter
w = (A v); % Solve A * w = v
v_new = w / norm(w); % Normalize the vector
% Check for convergence
if norm(v_new – v) < tol
break;
end
v = v_new; % Update the vector
end
% Calculate the corresponding eigenvalue
lambda = v’ * A * v;
% Normalize the eigenvector to have unit length
v = v / norm(v);
end
% Define the matrix A
A = [1, -3, 3;
3, -5, 3;
6, -6, 4];
% Set the tolerance and maximum number of iterations
tol = 1e-6;
max_iter = 1000;
% Call the inverse power method function
[lambda, v] = inverse_power_method(A, tol, max_iter);
% Display the results
fprintf(‘Estimated smallest eigenvalue: %.6fn’, lambda);
fprintf(‘Estimated corresponding eigenvector:n’);
disp(v); can you please see this accurate this to get answe MATLAB Answers — New Questions
Edge lines not drawn when adjacent patch is transparent
Hi!
I have a problem when rendering large 3D patches of cubes. Some of my patches are transparent and some are not. The edges drawn between vertices shared by a transparent face and a opaque face is not always shown. I’ve attached a small example of code showing this behaviour below, which mimics my full plot function.
clear; clc
FirstElementAlpha = 0.;
SecondElementAlpha = 0.8;
verts = [
0 0 0;
0 1 0;
0 0 1;
0 1 1;
1 0 0;
1 1 0;
1 0 1;
1 1 1;
2 0 0;
2 1 0;
2 0 1;
2 1 1;
];
faces = [
1 2 4 3;
2 4 8 6;
1 3 7 5;
5 6 8 7;
1 2 6 5;
3 4 8 7;
5 6 8 7;
6 8 12 10;
5 7 11 9;
9 10 12 11;
5 6 10 9;
7 8 12 11;
];
facealp = [
FirstElementAlpha*ones(6,1);
SecondElementAlpha*ones(6,1);
];
colormap pink
p = patch(‘Faces’,faces,’Vertices’,verts,’Facecolor’,’flat’,’EdgeAlpha’,’flat’,’FaceAlpha’,’flat’, …
‘FaceVertexAlphaData’,facealp,’FaceVertexCData’,1-facealp,’Linewidth’,2);
p.Parent.CLim = [0 1];
view(3)
axis equal
However, if flipping the transparancy of the two elements, all edges are shown.
I want the edges to always be drawn around faces, and the transparancy of this edge to be defined by the facealpha value. Im guessing that patch defines lines between vertices, and i overwrite a opaque line with a transparant line in my code.
Is there a way to keep the line with the largest alpha value?
Can i modify my plot function, to achieve this in another way?Hi!
I have a problem when rendering large 3D patches of cubes. Some of my patches are transparent and some are not. The edges drawn between vertices shared by a transparent face and a opaque face is not always shown. I’ve attached a small example of code showing this behaviour below, which mimics my full plot function.
clear; clc
FirstElementAlpha = 0.;
SecondElementAlpha = 0.8;
verts = [
0 0 0;
0 1 0;
0 0 1;
0 1 1;
1 0 0;
1 1 0;
1 0 1;
1 1 1;
2 0 0;
2 1 0;
2 0 1;
2 1 1;
];
faces = [
1 2 4 3;
2 4 8 6;
1 3 7 5;
5 6 8 7;
1 2 6 5;
3 4 8 7;
5 6 8 7;
6 8 12 10;
5 7 11 9;
9 10 12 11;
5 6 10 9;
7 8 12 11;
];
facealp = [
FirstElementAlpha*ones(6,1);
SecondElementAlpha*ones(6,1);
];
colormap pink
p = patch(‘Faces’,faces,’Vertices’,verts,’Facecolor’,’flat’,’EdgeAlpha’,’flat’,’FaceAlpha’,’flat’, …
‘FaceVertexAlphaData’,facealp,’FaceVertexCData’,1-facealp,’Linewidth’,2);
p.Parent.CLim = [0 1];
view(3)
axis equal
However, if flipping the transparancy of the two elements, all edges are shown.
I want the edges to always be drawn around faces, and the transparancy of this edge to be defined by the facealpha value. Im guessing that patch defines lines between vertices, and i overwrite a opaque line with a transparant line in my code.
Is there a way to keep the line with the largest alpha value?
Can i modify my plot function, to achieve this in another way? Hi!
I have a problem when rendering large 3D patches of cubes. Some of my patches are transparent and some are not. The edges drawn between vertices shared by a transparent face and a opaque face is not always shown. I’ve attached a small example of code showing this behaviour below, which mimics my full plot function.
clear; clc
FirstElementAlpha = 0.;
SecondElementAlpha = 0.8;
verts = [
0 0 0;
0 1 0;
0 0 1;
0 1 1;
1 0 0;
1 1 0;
1 0 1;
1 1 1;
2 0 0;
2 1 0;
2 0 1;
2 1 1;
];
faces = [
1 2 4 3;
2 4 8 6;
1 3 7 5;
5 6 8 7;
1 2 6 5;
3 4 8 7;
5 6 8 7;
6 8 12 10;
5 7 11 9;
9 10 12 11;
5 6 10 9;
7 8 12 11;
];
facealp = [
FirstElementAlpha*ones(6,1);
SecondElementAlpha*ones(6,1);
];
colormap pink
p = patch(‘Faces’,faces,’Vertices’,verts,’Facecolor’,’flat’,’EdgeAlpha’,’flat’,’FaceAlpha’,’flat’, …
‘FaceVertexAlphaData’,facealp,’FaceVertexCData’,1-facealp,’Linewidth’,2);
p.Parent.CLim = [0 1];
view(3)
axis equal
However, if flipping the transparancy of the two elements, all edges are shown.
I want the edges to always be drawn around faces, and the transparancy of this edge to be defined by the facealpha value. Im guessing that patch defines lines between vertices, and i overwrite a opaque line with a transparant line in my code.
Is there a way to keep the line with the largest alpha value?
Can i modify my plot function, to achieve this in another way? patch, alpha, edges, plotting MATLAB Answers — New Questions
How can I solve an equation using fixed point method?
g(x)=2^-x;
[1/3,1];
tol=10^-4;
max=100g(x)=2^-x;
[1/3,1];
tol=10^-4;
max=100 g(x)=2^-x;
[1/3,1];
tol=10^-4;
max=100 numerical analysis MATLAB Answers — New Questions
Error when simulating in Simulink
Error:Error in ‘untitled/Asynchronous Machine SI Units’: Failed to evaluate mask initialization commands.
Caused by:
Index exceeds the number of array elements. Index must not exceed 1.
How can i overcome this?Error:Error in ‘untitled/Asynchronous Machine SI Units’: Failed to evaluate mask initialization commands.
Caused by:
Index exceeds the number of array elements. Index must not exceed 1.
How can i overcome this? Error:Error in ‘untitled/Asynchronous Machine SI Units’: Failed to evaluate mask initialization commands.
Caused by:
Index exceeds the number of array elements. Index must not exceed 1.
How can i overcome this? asynchronous_simulink MATLAB Answers — New Questions
The estimation error is strangely obtained from Simpson’s 1/3 rule…
Hello, I am looking for the estimation error of Simpson’s rule of thirds. When dx is 1.01, the integral value is 2908800 and the error is 0.01, but the estimation error is 7.0844e-21. Where did it go wrong? I think In this part, the 5th coefficient is verry verry small, so it seems that the value will always be low. Isn’t the estimation error always accurate?
clc; clear all; close all;
a = -1.93317553181561E-24;
b = 3.788630291530091e-21;
c = -2.3447910280083294e-18
d = -0.019531249999999518;
e = 18.74999999999999
fun = @(t) a.*t.^5 + b.*t.^4 + c.*t.^3 + d.*t.^2+e.*t
x = 0:0.1:960;
fx =fun(x);
n=960;
dx=1.01;
int=0;
for i =1:n
plot(x, fx,’k’,’linewidth’,2);
mid=((i-1)+i)/2;
fx_mid = fun(mid);
fx_left = fun(i-1);
fx_right = fun(i);
area_temp = dx/6*(fx_left +4*fx_mid+fx_right);
int = int + area_temp;
x_segment = linspace(i-1, i,100);
Px = fx_left * ((x_segment-mid).*(x_segment-i))/((i-1-mid)*(i-1-i))…
+ fx_mid*((x_segment-i+1)).*(x_segment-i)/((mid-i+1)*(mid-i))…
+ fx_right * ((x_segment-i+1).*(x_segment-mid))/((i-i+1)*(i-mid));
area(x_segment,Px); hold on;
end
C=480;
E_a = -((960.^5)/(2880.*(960/1.01).^4)).*(a.*120.*C+24.*b);%Is there a problem here?
disp(‘E_a’);
disp(E_a);
disp(int);
int_true = 2880000
rel_error=norm(int_true-int)/norm(int_true);
disp(‘rel_error’);
disp(rel_error);Hello, I am looking for the estimation error of Simpson’s rule of thirds. When dx is 1.01, the integral value is 2908800 and the error is 0.01, but the estimation error is 7.0844e-21. Where did it go wrong? I think In this part, the 5th coefficient is verry verry small, so it seems that the value will always be low. Isn’t the estimation error always accurate?
clc; clear all; close all;
a = -1.93317553181561E-24;
b = 3.788630291530091e-21;
c = -2.3447910280083294e-18
d = -0.019531249999999518;
e = 18.74999999999999
fun = @(t) a.*t.^5 + b.*t.^4 + c.*t.^3 + d.*t.^2+e.*t
x = 0:0.1:960;
fx =fun(x);
n=960;
dx=1.01;
int=0;
for i =1:n
plot(x, fx,’k’,’linewidth’,2);
mid=((i-1)+i)/2;
fx_mid = fun(mid);
fx_left = fun(i-1);
fx_right = fun(i);
area_temp = dx/6*(fx_left +4*fx_mid+fx_right);
int = int + area_temp;
x_segment = linspace(i-1, i,100);
Px = fx_left * ((x_segment-mid).*(x_segment-i))/((i-1-mid)*(i-1-i))…
+ fx_mid*((x_segment-i+1)).*(x_segment-i)/((mid-i+1)*(mid-i))…
+ fx_right * ((x_segment-i+1).*(x_segment-mid))/((i-i+1)*(i-mid));
area(x_segment,Px); hold on;
end
C=480;
E_a = -((960.^5)/(2880.*(960/1.01).^4)).*(a.*120.*C+24.*b);%Is there a problem here?
disp(‘E_a’);
disp(E_a);
disp(int);
int_true = 2880000
rel_error=norm(int_true-int)/norm(int_true);
disp(‘rel_error’);
disp(rel_error); Hello, I am looking for the estimation error of Simpson’s rule of thirds. When dx is 1.01, the integral value is 2908800 and the error is 0.01, but the estimation error is 7.0844e-21. Where did it go wrong? I think In this part, the 5th coefficient is verry verry small, so it seems that the value will always be low. Isn’t the estimation error always accurate?
clc; clear all; close all;
a = -1.93317553181561E-24;
b = 3.788630291530091e-21;
c = -2.3447910280083294e-18
d = -0.019531249999999518;
e = 18.74999999999999
fun = @(t) a.*t.^5 + b.*t.^4 + c.*t.^3 + d.*t.^2+e.*t
x = 0:0.1:960;
fx =fun(x);
n=960;
dx=1.01;
int=0;
for i =1:n
plot(x, fx,’k’,’linewidth’,2);
mid=((i-1)+i)/2;
fx_mid = fun(mid);
fx_left = fun(i-1);
fx_right = fun(i);
area_temp = dx/6*(fx_left +4*fx_mid+fx_right);
int = int + area_temp;
x_segment = linspace(i-1, i,100);
Px = fx_left * ((x_segment-mid).*(x_segment-i))/((i-1-mid)*(i-1-i))…
+ fx_mid*((x_segment-i+1)).*(x_segment-i)/((mid-i+1)*(mid-i))…
+ fx_right * ((x_segment-i+1).*(x_segment-mid))/((i-i+1)*(i-mid));
area(x_segment,Px); hold on;
end
C=480;
E_a = -((960.^5)/(2880.*(960/1.01).^4)).*(a.*120.*C+24.*b);%Is there a problem here?
disp(‘E_a’);
disp(E_a);
disp(int);
int_true = 2880000
rel_error=norm(int_true-int)/norm(int_true);
disp(‘rel_error’);
disp(rel_error); simpson’s 1/3 rule, estimation error, matlab code MATLAB Answers — New Questions
how can I change worldmap axes grid and label?
Hi, I am trying to make a map with spesific lat and lon degrees. And I want to make labelling and grids on 26 E, 29 E, 32 E, 35 E,38, E41 E,44 E. But whatever I tried the labelling and grid never start from 26 E. I add my result picture below. Please help me.
clear all
close all
clc
xmin = 26;
xmax = 44.6;
ymin = 34;
ymax = 42.5;
latlim = [ymin ymax];
lonlim = [xmin xmax];
w=worldmap(latlim,lonlim)
p=findobj(w,’Tag’,’Parallel’);
m=findobj(w,’Tag’,’Meridian’);
p.LineWidth = 1.5;
p.Color=’red’;
m.LineWidth = 1.5;
m.Color=’red’;
bordersm(‘Turkey’)
bordersm(‘Cyprus’)Hi, I am trying to make a map with spesific lat and lon degrees. And I want to make labelling and grids on 26 E, 29 E, 32 E, 35 E,38, E41 E,44 E. But whatever I tried the labelling and grid never start from 26 E. I add my result picture below. Please help me.
clear all
close all
clc
xmin = 26;
xmax = 44.6;
ymin = 34;
ymax = 42.5;
latlim = [ymin ymax];
lonlim = [xmin xmax];
w=worldmap(latlim,lonlim)
p=findobj(w,’Tag’,’Parallel’);
m=findobj(w,’Tag’,’Meridian’);
p.LineWidth = 1.5;
p.Color=’red’;
m.LineWidth = 1.5;
m.Color=’red’;
bordersm(‘Turkey’)
bordersm(‘Cyprus’) Hi, I am trying to make a map with spesific lat and lon degrees. And I want to make labelling and grids on 26 E, 29 E, 32 E, 35 E,38, E41 E,44 E. But whatever I tried the labelling and grid never start from 26 E. I add my result picture below. Please help me.
clear all
close all
clc
xmin = 26;
xmax = 44.6;
ymin = 34;
ymax = 42.5;
latlim = [ymin ymax];
lonlim = [xmin xmax];
w=worldmap(latlim,lonlim)
p=findobj(w,’Tag’,’Parallel’);
m=findobj(w,’Tag’,’Meridian’);
p.LineWidth = 1.5;
p.Color=’red’;
m.LineWidth = 1.5;
m.Color=’red’;
bordersm(‘Turkey’)
bordersm(‘Cyprus’) worldmap MATLAB Answers — New Questions
MCR .Net using Native Dll, data type unsupported by matlab
Hi there.
i have a MATLAB function that returns a struct (Instace) and a string (Json)
function [Instance,Json] = Process(path)
% Some Work
end
i am compiling this function into .Net dll and taking the native.dll file.
then i run this function from c#, and i get this error
"Data type unsupported by MATLAB .NET Assembly for conversion to array"
which means that the MCR can’t convert the struct (Insrance) into a .Net object.
if i remove the struct (Instace), it works fine.
Q:
is there a way to ignore this parameter?, without returning just the Json.
it need to return both of them.
i don’t need it just the json.
Thanks!Hi there.
i have a MATLAB function that returns a struct (Instace) and a string (Json)
function [Instance,Json] = Process(path)
% Some Work
end
i am compiling this function into .Net dll and taking the native.dll file.
then i run this function from c#, and i get this error
"Data type unsupported by MATLAB .NET Assembly for conversion to array"
which means that the MCR can’t convert the struct (Insrance) into a .Net object.
if i remove the struct (Instace), it works fine.
Q:
is there a way to ignore this parameter?, without returning just the Json.
it need to return both of them.
i don’t need it just the json.
Thanks! Hi there.
i have a MATLAB function that returns a struct (Instace) and a string (Json)
function [Instance,Json] = Process(path)
% Some Work
end
i am compiling this function into .Net dll and taking the native.dll file.
then i run this function from c#, and i get this error
"Data type unsupported by MATLAB .NET Assembly for conversion to array"
which means that the MCR can’t convert the struct (Insrance) into a .Net object.
if i remove the struct (Instace), it works fine.
Q:
is there a way to ignore this parameter?, without returning just the Json.
it need to return both of them.
i don’t need it just the json.
Thanks! mcr, .net, data type, c#, convert MATLAB Answers — New Questions
Using state space in simulink
What does x represent in the state space I define in simulink?What does x represent in the state space I define in simulink? What does x represent in the state space I define in simulink? state-space, state vector, simulink MATLAB Answers — New Questions
How to create a table with interpreter latex?
How to create a table with interpreter latex?
In the following example, I would like to have the text inside the table with interpreter latex:
dates = {‘1$-$2 May 2024′,’2$-$3 May 2024′,’3$-$4 May 2024′,’4$-$5 May 2024′,’5$-$6 May 2024’};
for i = 1 : 5
a(i) = 2*i;
b(i) = sqrt(i);
c(i,:) = [{sprintf(‘date: %s, class: %d’,dates{i},i)} a(i) b(i)];
end
T = table(c(:,1),c(:,2),c(:,3),’VariableNames’,{‘date&class’,’a’,’b’})
How to do it?How to create a table with interpreter latex?
In the following example, I would like to have the text inside the table with interpreter latex:
dates = {‘1$-$2 May 2024′,’2$-$3 May 2024′,’3$-$4 May 2024′,’4$-$5 May 2024′,’5$-$6 May 2024’};
for i = 1 : 5
a(i) = 2*i;
b(i) = sqrt(i);
c(i,:) = [{sprintf(‘date: %s, class: %d’,dates{i},i)} a(i) b(i)];
end
T = table(c(:,1),c(:,2),c(:,3),’VariableNames’,{‘date&class’,’a’,’b’})
How to do it? How to create a table with interpreter latex?
In the following example, I would like to have the text inside the table with interpreter latex:
dates = {‘1$-$2 May 2024′,’2$-$3 May 2024′,’3$-$4 May 2024′,’4$-$5 May 2024′,’5$-$6 May 2024’};
for i = 1 : 5
a(i) = 2*i;
b(i) = sqrt(i);
c(i,:) = [{sprintf(‘date: %s, class: %d’,dates{i},i)} a(i) b(i)];
end
T = table(c(:,1),c(:,2),c(:,3),’VariableNames’,{‘date&class’,’a’,’b’})
How to do it? table, interpreter, latex, sprintf MATLAB Answers — New Questions
Matlab To Snowflake Data Warehouse
Any recommendations or best practices for how best to connect Matlab to Snowflake date wareshouse.Any recommendations or best practices for how best to connect Matlab to Snowflake date wareshouse. Any recommendations or best practices for how best to connect Matlab to Snowflake date wareshouse. database, odbc, jdbc MATLAB Answers — New Questions
What is the reference for the power/frequency scale bar on the right in Spectrogram?
Dear experts,
Can anyone help me how to get the power/frequency scale in Spectrogram using STFT?
What is the reference for the power/frequency scale bar on the right?
Additionally, how to plot actual time interval? I want it to plot on the time axis from for exp. 5083s time span but using the spectrogram built in function plots from 0 s as seen below.
I appreciate if anyone can help me with this.Dear experts,
Can anyone help me how to get the power/frequency scale in Spectrogram using STFT?
What is the reference for the power/frequency scale bar on the right?
Additionally, how to plot actual time interval? I want it to plot on the time axis from for exp. 5083s time span but using the spectrogram built in function plots from 0 s as seen below.
I appreciate if anyone can help me with this. Dear experts,
Can anyone help me how to get the power/frequency scale in Spectrogram using STFT?
What is the reference for the power/frequency scale bar on the right?
Additionally, how to plot actual time interval? I want it to plot on the time axis from for exp. 5083s time span but using the spectrogram built in function plots from 0 s as seen below.
I appreciate if anyone can help me with this. spectrogram, stft, actual time interval, power/frequency reference MATLAB Answers — New Questions
The estimation error is strangely obtained from Simpson’s 1/3 rule
Hello, I am looking for the estimation error of Simpson’s rule of thirds. When dx is 1.01, the integral value is 2908800 and the error is 0.01, but the estimation error is 5.5567e-09. Where did it go wrong?
clc; clear all; close all;
a = -1.93317553181561E-24;
b = 3.788630291530091e-21;
c = -2.3447910280083294e-18
d = -0.019531249999999518;
e = 18.74999999999999
fun = @(t) a.*t.^5 + b.*t.^4 + c.*t.^3 + d.*t.^2+e.*t
x = 0:0.1:960;
fx =fun(x);
n=960;
dx=1.01
int=0;
for i =1:n
plot(x, fx,’k’,’linewidth’,2);
mid=((i-1)+i)/2;
fx_mid = fun(mid);
fx_left = fun(i-1);
fx_right = fun(i);
area_temp = dx/6*(fx_left +4*fx_mid+fx_right);
int = int + area_temp;
x_segment = linspace(i-1, i,100);
Px = fx_left * ((x_segment-mid).*(x_segment-i))/((i-1-mid)*(i-1-i))…
+ fx_mid*((x_segment-i+1)).*(x_segment-i)/((mid-i+1)*(mid-i))…
+ fx_right * ((x_segment-i+1).*(x_segment-mid))/((i-i+1)*(i-mid));
area(x_segment,Px); hold on;
end
C=480;
E_a = -((960.^5)/(2880.*1.01.^4)).*(a.*120.*C+24.*b);%Is there a problem here?
disp(‘E_a’);
disp(E_a);
disp(int);
int_true = 2880000
rel_error=norm(int_true-int)/norm(int_true);
disp(‘rel_error’);
disp(rel_error);Hello, I am looking for the estimation error of Simpson’s rule of thirds. When dx is 1.01, the integral value is 2908800 and the error is 0.01, but the estimation error is 5.5567e-09. Where did it go wrong?
clc; clear all; close all;
a = -1.93317553181561E-24;
b = 3.788630291530091e-21;
c = -2.3447910280083294e-18
d = -0.019531249999999518;
e = 18.74999999999999
fun = @(t) a.*t.^5 + b.*t.^4 + c.*t.^3 + d.*t.^2+e.*t
x = 0:0.1:960;
fx =fun(x);
n=960;
dx=1.01
int=0;
for i =1:n
plot(x, fx,’k’,’linewidth’,2);
mid=((i-1)+i)/2;
fx_mid = fun(mid);
fx_left = fun(i-1);
fx_right = fun(i);
area_temp = dx/6*(fx_left +4*fx_mid+fx_right);
int = int + area_temp;
x_segment = linspace(i-1, i,100);
Px = fx_left * ((x_segment-mid).*(x_segment-i))/((i-1-mid)*(i-1-i))…
+ fx_mid*((x_segment-i+1)).*(x_segment-i)/((mid-i+1)*(mid-i))…
+ fx_right * ((x_segment-i+1).*(x_segment-mid))/((i-i+1)*(i-mid));
area(x_segment,Px); hold on;
end
C=480;
E_a = -((960.^5)/(2880.*1.01.^4)).*(a.*120.*C+24.*b);%Is there a problem here?
disp(‘E_a’);
disp(E_a);
disp(int);
int_true = 2880000
rel_error=norm(int_true-int)/norm(int_true);
disp(‘rel_error’);
disp(rel_error); Hello, I am looking for the estimation error of Simpson’s rule of thirds. When dx is 1.01, the integral value is 2908800 and the error is 0.01, but the estimation error is 5.5567e-09. Where did it go wrong?
clc; clear all; close all;
a = -1.93317553181561E-24;
b = 3.788630291530091e-21;
c = -2.3447910280083294e-18
d = -0.019531249999999518;
e = 18.74999999999999
fun = @(t) a.*t.^5 + b.*t.^4 + c.*t.^3 + d.*t.^2+e.*t
x = 0:0.1:960;
fx =fun(x);
n=960;
dx=1.01
int=0;
for i =1:n
plot(x, fx,’k’,’linewidth’,2);
mid=((i-1)+i)/2;
fx_mid = fun(mid);
fx_left = fun(i-1);
fx_right = fun(i);
area_temp = dx/6*(fx_left +4*fx_mid+fx_right);
int = int + area_temp;
x_segment = linspace(i-1, i,100);
Px = fx_left * ((x_segment-mid).*(x_segment-i))/((i-1-mid)*(i-1-i))…
+ fx_mid*((x_segment-i+1)).*(x_segment-i)/((mid-i+1)*(mid-i))…
+ fx_right * ((x_segment-i+1).*(x_segment-mid))/((i-i+1)*(i-mid));
area(x_segment,Px); hold on;
end
C=480;
E_a = -((960.^5)/(2880.*1.01.^4)).*(a.*120.*C+24.*b);%Is there a problem here?
disp(‘E_a’);
disp(E_a);
disp(int);
int_true = 2880000
rel_error=norm(int_true-int)/norm(int_true);
disp(‘rel_error’);
disp(rel_error); simpson’s 1/3 rule, estimation error MATLAB Answers — New Questions
why are the results different from moist air domain(MA) using only dry air and gas domain(G)? – simscape
Hello, I used Simscape to model with the constant volume chamber, local restriction, and controlled heat flow rate source blocks. I used the semi-ideal gas and now I’m trying to switch to the moist air domain to include gases with different properties. I modeled it the same way as before and set the humidity ratio to 0 to ensure there is no water vapor. However, the results are significantly different. Are there any conditions I might have overlooked?Hello, I used Simscape to model with the constant volume chamber, local restriction, and controlled heat flow rate source blocks. I used the semi-ideal gas and now I’m trying to switch to the moist air domain to include gases with different properties. I modeled it the same way as before and set the humidity ratio to 0 to ensure there is no water vapor. However, the results are significantly different. Are there any conditions I might have overlooked? Hello, I used Simscape to model with the constant volume chamber, local restriction, and controlled heat flow rate source blocks. I used the semi-ideal gas and now I’m trying to switch to the moist air domain to include gases with different properties. I modeled it the same way as before and set the humidity ratio to 0 to ensure there is no water vapor. However, the results are significantly different. Are there any conditions I might have overlooked? ma, trace gas MATLAB Answers — New Questions
Trying to merge two tables, using time stamps as keys in outerjoin(), getting ‘incorrect data type or missing argument’ error.
Hi!
I have two tables, each with two rows. One is ‘raw’, and has each possible time stamp and corresponding data. The other is ‘valid’, and only has time stamps corresponding to valid data. I want to have a third table, that contains all time stamps but NaNs where there isn’t both raw and valid data.
So, for example, these would go into outerjoin()
valid = ‘t_ms’ ‘val_dat’
[ 1 55
2 50
4 52 ]
raw = [ 1 49
2 37
3 51
4 52 ]
And I’d get a table that’s the length of ‘raw’, and ‘valid’ containing NaNs. Instead, I get the error:
‘Check for incorrect argument data type or missing argument in call to outerjoin.’
I’ve quadruple checked that I’m inputting tables, and the key variables have the exact same name, and I’ve tried pretty much every optional argument into outerjoin() I can, no dice.
Any help would be much appreciated, embarrassingly enough I’m stumped!
ThanksHi!
I have two tables, each with two rows. One is ‘raw’, and has each possible time stamp and corresponding data. The other is ‘valid’, and only has time stamps corresponding to valid data. I want to have a third table, that contains all time stamps but NaNs where there isn’t both raw and valid data.
So, for example, these would go into outerjoin()
valid = ‘t_ms’ ‘val_dat’
[ 1 55
2 50
4 52 ]
raw = [ 1 49
2 37
3 51
4 52 ]
And I’d get a table that’s the length of ‘raw’, and ‘valid’ containing NaNs. Instead, I get the error:
‘Check for incorrect argument data type or missing argument in call to outerjoin.’
I’ve quadruple checked that I’m inputting tables, and the key variables have the exact same name, and I’ve tried pretty much every optional argument into outerjoin() I can, no dice.
Any help would be much appreciated, embarrassingly enough I’m stumped!
Thanks Hi!
I have two tables, each with two rows. One is ‘raw’, and has each possible time stamp and corresponding data. The other is ‘valid’, and only has time stamps corresponding to valid data. I want to have a third table, that contains all time stamps but NaNs where there isn’t both raw and valid data.
So, for example, these would go into outerjoin()
valid = ‘t_ms’ ‘val_dat’
[ 1 55
2 50
4 52 ]
raw = [ 1 49
2 37
3 51
4 52 ]
And I’d get a table that’s the length of ‘raw’, and ‘valid’ containing NaNs. Instead, I get the error:
‘Check for incorrect argument data type or missing argument in call to outerjoin.’
I’ve quadruple checked that I’m inputting tables, and the key variables have the exact same name, and I’ve tried pretty much every optional argument into outerjoin() I can, no dice.
Any help would be much appreciated, embarrassingly enough I’m stumped!
Thanks outerjoin, tables, datatype MATLAB Answers — New Questions
I’d like to make several ‘figure’ window
I want to add two figure windows, but <figure 2> window doesn’t show up.
<code>
%상태 방정식
%Dx1 = -x1 – x2 + u1 + u2
%Dx2 = 6.5*x1 + u1
%y1 = x1
%y2 = x2
t = 0:0.01:15;
A = [-1 -1;6.5 0];
B = [1 1;1 0];
C = [1 0;0 1];
D = [0 0;0 0];
sys = ss(A,B,C,D);
impulse(sys,t);
[y,t,x] = impulse(sys,t);
y1 = [1 0]*y(:,:,1)’ + [1 0]*y(:,:,2)’;
y2 = [0 1]*y(:,:,1)’ + [0 1]*y(:,:,2)’;
figure(1)
plot(t,sys)
xlabel(‘Time,(s)’)
ylabel(‘y’)
grid;
legend(‘y’)
figure(2)
subplot(211);
plot(t, y1); grid
ylabel(‘y_1’)
subplot(212);
plot(t, y2); grid
xlabel(‘t (sec)’); ylabel(‘y_2’)I want to add two figure windows, but <figure 2> window doesn’t show up.
<code>
%상태 방정식
%Dx1 = -x1 – x2 + u1 + u2
%Dx2 = 6.5*x1 + u1
%y1 = x1
%y2 = x2
t = 0:0.01:15;
A = [-1 -1;6.5 0];
B = [1 1;1 0];
C = [1 0;0 1];
D = [0 0;0 0];
sys = ss(A,B,C,D);
impulse(sys,t);
[y,t,x] = impulse(sys,t);
y1 = [1 0]*y(:,:,1)’ + [1 0]*y(:,:,2)’;
y2 = [0 1]*y(:,:,1)’ + [0 1]*y(:,:,2)’;
figure(1)
plot(t,sys)
xlabel(‘Time,(s)’)
ylabel(‘y’)
grid;
legend(‘y’)
figure(2)
subplot(211);
plot(t, y1); grid
ylabel(‘y_1’)
subplot(212);
plot(t, y2); grid
xlabel(‘t (sec)’); ylabel(‘y_2’) I want to add two figure windows, but <figure 2> window doesn’t show up.
<code>
%상태 방정식
%Dx1 = -x1 – x2 + u1 + u2
%Dx2 = 6.5*x1 + u1
%y1 = x1
%y2 = x2
t = 0:0.01:15;
A = [-1 -1;6.5 0];
B = [1 1;1 0];
C = [1 0;0 1];
D = [0 0;0 0];
sys = ss(A,B,C,D);
impulse(sys,t);
[y,t,x] = impulse(sys,t);
y1 = [1 0]*y(:,:,1)’ + [1 0]*y(:,:,2)’;
y2 = [0 1]*y(:,:,1)’ + [0 1]*y(:,:,2)’;
figure(1)
plot(t,sys)
xlabel(‘Time,(s)’)
ylabel(‘y’)
grid;
legend(‘y’)
figure(2)
subplot(211);
plot(t, y1); grid
ylabel(‘y_1’)
subplot(212);
plot(t, y2); grid
xlabel(‘t (sec)’); ylabel(‘y_2’) matlab MATLAB Answers — New Questions
An optimization with fmincon
Hello everyone, sorry for the inconvenience. I would have a problem with the optimization via the fmincon function. I wanted to ask, kindly, if anyone could help me. I need to get 3 parameters (x1, x2, x3 = 0.4242 0.2928 0.2830; max = 319). Thanks to who will answer me. Good day.
%% FITTING MODEL
%———————————————–
clc, clear
global x1s x2s x3s rs
global betax
data = [100 0 0 265
0 100 0 170
0 0 100 119
50 50 0 252
50 0 50 247
0 50 50 222
66.67 16.67 16.67 310
16.67 66.67 16.67 244
16.67 16.67 66.67 239
33.33 33.33 33.33 322
100 0 0 257
0 100 0 181
0 0 100 127];
x1s = data(:,1)/100; % values of x1
x2s = data(:,2)/100; % values of x2
x3s = data(:,3)/100; % values of x1
rs = data(:,4); % values of residual
% function
beta0 = [62.8 173.1 122.6 131.0 228.2 274.2 1597.9];
beta=lsqnonlin(‘funzione’,beta0);
for j=1:length(rs)
rc(j)= modello(x1s(j),x2s(j),x3s(j));
res(j) = rc(j) – rs(j);
end
%% data calculation
betax = beta;
ndat=10000;
for j=1:ndat
x1c(j) = rand(1,1);
x2c(j) = rand(1,1)*(1-x1c(j));
x3c(j) = 1-x1c(j)-x2c(j);
risp(j) = modello(x1c(j),x2c(j),x3c(j));
end
%% diagram
figure(1);
% plot of data
% colour
% test surface response
colormap (jet)
[hg,htick,hcb] = tersurf(x1c,x2c,x3c,risp);
% axes label
hlabels = terlabel(‘x1′,’x2′,’x3’);
%% experiment
figure(2)
%– Plot axis
[h,hg,htick] = terplot;
%– Plot data
hter = ternaryc(x1s,x2s,x3s);
set(hter,’marker’,’o’,’markerfacecolor’,’blue’,’markersize’,’8′)
hlabels = terlabel(‘x1′,’x2′,’x3’);
%% residual plot
figure(3)
plot(x1s,res,’ro’)
xlabel(‘x1’)
ylabel(‘residui’)
grid
%% NORMAL PROBABILITY GRAPH
figure(4)
res_sort = sort(res);
for j = 1:length(res)
xj(j) = j/(length(res)-1);
end
semilogy(res_sort,xj,’ko’)
grid
%% SEARCH FOR THE MINIMUM
x0 = [0.3 0.3 0.3]; % punto centrale
lb = [0 0 0]; % limite inferiore
ub = [1 1 1]; % limite superiore
Aeq = [1 1 1];
beq = 1;
y = fmincon(‘funz’,x0,[],[],Aeq,beq,lb,ub)
modello(xmax(1),xmax(2),xmax(3))
function [z] = funz (x1s,x2s,x3s)
global x1s x2s x3s
z = 62.8.*x1s+173.1.*x2s+122.6.*x3s+131.0.*x1s*x2s+228.2.*x1s*x3s+274.2.*x2s*x3s+1597.9.*x1s*x2s*x3s;
endHello everyone, sorry for the inconvenience. I would have a problem with the optimization via the fmincon function. I wanted to ask, kindly, if anyone could help me. I need to get 3 parameters (x1, x2, x3 = 0.4242 0.2928 0.2830; max = 319). Thanks to who will answer me. Good day.
%% FITTING MODEL
%———————————————–
clc, clear
global x1s x2s x3s rs
global betax
data = [100 0 0 265
0 100 0 170
0 0 100 119
50 50 0 252
50 0 50 247
0 50 50 222
66.67 16.67 16.67 310
16.67 66.67 16.67 244
16.67 16.67 66.67 239
33.33 33.33 33.33 322
100 0 0 257
0 100 0 181
0 0 100 127];
x1s = data(:,1)/100; % values of x1
x2s = data(:,2)/100; % values of x2
x3s = data(:,3)/100; % values of x1
rs = data(:,4); % values of residual
% function
beta0 = [62.8 173.1 122.6 131.0 228.2 274.2 1597.9];
beta=lsqnonlin(‘funzione’,beta0);
for j=1:length(rs)
rc(j)= modello(x1s(j),x2s(j),x3s(j));
res(j) = rc(j) – rs(j);
end
%% data calculation
betax = beta;
ndat=10000;
for j=1:ndat
x1c(j) = rand(1,1);
x2c(j) = rand(1,1)*(1-x1c(j));
x3c(j) = 1-x1c(j)-x2c(j);
risp(j) = modello(x1c(j),x2c(j),x3c(j));
end
%% diagram
figure(1);
% plot of data
% colour
% test surface response
colormap (jet)
[hg,htick,hcb] = tersurf(x1c,x2c,x3c,risp);
% axes label
hlabels = terlabel(‘x1′,’x2′,’x3’);
%% experiment
figure(2)
%– Plot axis
[h,hg,htick] = terplot;
%– Plot data
hter = ternaryc(x1s,x2s,x3s);
set(hter,’marker’,’o’,’markerfacecolor’,’blue’,’markersize’,’8′)
hlabels = terlabel(‘x1′,’x2′,’x3’);
%% residual plot
figure(3)
plot(x1s,res,’ro’)
xlabel(‘x1’)
ylabel(‘residui’)
grid
%% NORMAL PROBABILITY GRAPH
figure(4)
res_sort = sort(res);
for j = 1:length(res)
xj(j) = j/(length(res)-1);
end
semilogy(res_sort,xj,’ko’)
grid
%% SEARCH FOR THE MINIMUM
x0 = [0.3 0.3 0.3]; % punto centrale
lb = [0 0 0]; % limite inferiore
ub = [1 1 1]; % limite superiore
Aeq = [1 1 1];
beq = 1;
y = fmincon(‘funz’,x0,[],[],Aeq,beq,lb,ub)
modello(xmax(1),xmax(2),xmax(3))
function [z] = funz (x1s,x2s,x3s)
global x1s x2s x3s
z = 62.8.*x1s+173.1.*x2s+122.6.*x3s+131.0.*x1s*x2s+228.2.*x1s*x3s+274.2.*x2s*x3s+1597.9.*x1s*x2s*x3s;
end Hello everyone, sorry for the inconvenience. I would have a problem with the optimization via the fmincon function. I wanted to ask, kindly, if anyone could help me. I need to get 3 parameters (x1, x2, x3 = 0.4242 0.2928 0.2830; max = 319). Thanks to who will answer me. Good day.
%% FITTING MODEL
%———————————————–
clc, clear
global x1s x2s x3s rs
global betax
data = [100 0 0 265
0 100 0 170
0 0 100 119
50 50 0 252
50 0 50 247
0 50 50 222
66.67 16.67 16.67 310
16.67 66.67 16.67 244
16.67 16.67 66.67 239
33.33 33.33 33.33 322
100 0 0 257
0 100 0 181
0 0 100 127];
x1s = data(:,1)/100; % values of x1
x2s = data(:,2)/100; % values of x2
x3s = data(:,3)/100; % values of x1
rs = data(:,4); % values of residual
% function
beta0 = [62.8 173.1 122.6 131.0 228.2 274.2 1597.9];
beta=lsqnonlin(‘funzione’,beta0);
for j=1:length(rs)
rc(j)= modello(x1s(j),x2s(j),x3s(j));
res(j) = rc(j) – rs(j);
end
%% data calculation
betax = beta;
ndat=10000;
for j=1:ndat
x1c(j) = rand(1,1);
x2c(j) = rand(1,1)*(1-x1c(j));
x3c(j) = 1-x1c(j)-x2c(j);
risp(j) = modello(x1c(j),x2c(j),x3c(j));
end
%% diagram
figure(1);
% plot of data
% colour
% test surface response
colormap (jet)
[hg,htick,hcb] = tersurf(x1c,x2c,x3c,risp);
% axes label
hlabels = terlabel(‘x1′,’x2′,’x3’);
%% experiment
figure(2)
%– Plot axis
[h,hg,htick] = terplot;
%– Plot data
hter = ternaryc(x1s,x2s,x3s);
set(hter,’marker’,’o’,’markerfacecolor’,’blue’,’markersize’,’8′)
hlabels = terlabel(‘x1′,’x2′,’x3’);
%% residual plot
figure(3)
plot(x1s,res,’ro’)
xlabel(‘x1’)
ylabel(‘residui’)
grid
%% NORMAL PROBABILITY GRAPH
figure(4)
res_sort = sort(res);
for j = 1:length(res)
xj(j) = j/(length(res)-1);
end
semilogy(res_sort,xj,’ko’)
grid
%% SEARCH FOR THE MINIMUM
x0 = [0.3 0.3 0.3]; % punto centrale
lb = [0 0 0]; % limite inferiore
ub = [1 1 1]; % limite superiore
Aeq = [1 1 1];
beq = 1;
y = fmincon(‘funz’,x0,[],[],Aeq,beq,lb,ub)
modello(xmax(1),xmax(2),xmax(3))
function [z] = funz (x1s,x2s,x3s)
global x1s x2s x3s
z = 62.8.*x1s+173.1.*x2s+122.6.*x3s+131.0.*x1s*x2s+228.2.*x1s*x3s+274.2.*x2s*x3s+1597.9.*x1s*x2s*x3s;
end help fmincon, help-fmincon MATLAB Answers — New Questions
Ethernet-Based AXI Manager Error
Hello,
I am trying to implement MathWorks example described in: https://www.mathworks.com/help/hdlverifier/xilinxfpgaboards/ug/access-fpga-mem-using-ethernet-aximaster.html
The board I am trying to use is the Xilinx AC701. Reading throughout MathWorks documentation there is nothing that indicates the example could not work for this board. It is just not part of the supported boards but the specifications are very similar to the one being used in that example (KC705).
I was able to implement the example in my board’s FPGA and I can see the ethernet port alive in my PC using WireShark. However, I am not able to create an aximanager ethernet object as the following error appears:
Error using hdlverifier.AXIManagerUDP
Unable to ping the device. Please check the hardware IP address, the Ethernet cable connection, and the configuration of the
Network Interface Card.
Error in hdlverifier.AXIManagerUDP
Error in aximanager
I set the PC IP to 192.168.0.10 and the gateway to 192.168.0.2
This is what I se on the ethernet status:
The code I am using to create the aximanager object is:
hDDR = aximanager(‘Xilinx’,’interface’,’Ethernet’, …
‘DeviceAddress’,’192.168.0.2′);
writememory(hDDR,’00000000′,100);
readmemory(hDDR,’00000000′,1);
The erro I am receiving is:
I am using Matalab R2023b and Vivado 2022.1
Any idea of what I am doing wrong and why I am receiving this error?
Thank you,Hello,
I am trying to implement MathWorks example described in: https://www.mathworks.com/help/hdlverifier/xilinxfpgaboards/ug/access-fpga-mem-using-ethernet-aximaster.html
The board I am trying to use is the Xilinx AC701. Reading throughout MathWorks documentation there is nothing that indicates the example could not work for this board. It is just not part of the supported boards but the specifications are very similar to the one being used in that example (KC705).
I was able to implement the example in my board’s FPGA and I can see the ethernet port alive in my PC using WireShark. However, I am not able to create an aximanager ethernet object as the following error appears:
Error using hdlverifier.AXIManagerUDP
Unable to ping the device. Please check the hardware IP address, the Ethernet cable connection, and the configuration of the
Network Interface Card.
Error in hdlverifier.AXIManagerUDP
Error in aximanager
I set the PC IP to 192.168.0.10 and the gateway to 192.168.0.2
This is what I se on the ethernet status:
The code I am using to create the aximanager object is:
hDDR = aximanager(‘Xilinx’,’interface’,’Ethernet’, …
‘DeviceAddress’,’192.168.0.2′);
writememory(hDDR,’00000000′,100);
readmemory(hDDR,’00000000′,1);
The erro I am receiving is:
I am using Matalab R2023b and Vivado 2022.1
Any idea of what I am doing wrong and why I am receiving this error?
Thank you, Hello,
I am trying to implement MathWorks example described in: https://www.mathworks.com/help/hdlverifier/xilinxfpgaboards/ug/access-fpga-mem-using-ethernet-aximaster.html
The board I am trying to use is the Xilinx AC701. Reading throughout MathWorks documentation there is nothing that indicates the example could not work for this board. It is just not part of the supported boards but the specifications are very similar to the one being used in that example (KC705).
I was able to implement the example in my board’s FPGA and I can see the ethernet port alive in my PC using WireShark. However, I am not able to create an aximanager ethernet object as the following error appears:
Error using hdlverifier.AXIManagerUDP
Unable to ping the device. Please check the hardware IP address, the Ethernet cable connection, and the configuration of the
Network Interface Card.
Error in hdlverifier.AXIManagerUDP
Error in aximanager
I set the PC IP to 192.168.0.10 and the gateway to 192.168.0.2
This is what I se on the ethernet status:
The code I am using to create the aximanager object is:
hDDR = aximanager(‘Xilinx’,’interface’,’Ethernet’, …
‘DeviceAddress’,’192.168.0.2′);
writememory(hDDR,’00000000′,100);
readmemory(hDDR,’00000000′,1);
The erro I am receiving is:
I am using Matalab R2023b and Vivado 2022.1
Any idea of what I am doing wrong and why I am receiving this error?
Thank you, aximanager, matlab MATLAB Answers — New Questions
How can I declare an implicit variable, y(t), after I have used it in a symbolically defined function?
I’m writing a scheme that solves an ODE and in doing so I declare a symbolic function:
syms t y(t)
f = t^(-2) * (sin(2*t) – 2*t*y)
At one point I have to take a total derivative, so I need to be be implicit in the expression, but I also need to evalute at a specific value of and . I attempt to do this in the following lines.
y(t) = wi;
out(1) = f(ti);
However, I am prompted with the following error.
The following error occurred converting from sym to double:
Unable to convert expression containing remaining symbolic
function calls into double array. Argument must be
expression that evaluates to number.
Error in DiffEq_alt (line 13)
out(1) = f(ti);
Ultimately, I need to be able to be able to declare explicitly, but also treat it implicitly for when I differentiate the function with respect to .I’m writing a scheme that solves an ODE and in doing so I declare a symbolic function:
syms t y(t)
f = t^(-2) * (sin(2*t) – 2*t*y)
At one point I have to take a total derivative, so I need to be be implicit in the expression, but I also need to evalute at a specific value of and . I attempt to do this in the following lines.
y(t) = wi;
out(1) = f(ti);
However, I am prompted with the following error.
The following error occurred converting from sym to double:
Unable to convert expression containing remaining symbolic
function calls into double array. Argument must be
expression that evaluates to number.
Error in DiffEq_alt (line 13)
out(1) = f(ti);
Ultimately, I need to be able to be able to declare explicitly, but also treat it implicitly for when I differentiate the function with respect to . I’m writing a scheme that solves an ODE and in doing so I declare a symbolic function:
syms t y(t)
f = t^(-2) * (sin(2*t) – 2*t*y)
At one point I have to take a total derivative, so I need to be be implicit in the expression, but I also need to evalute at a specific value of and . I attempt to do this in the following lines.
y(t) = wi;
out(1) = f(ti);
However, I am prompted with the following error.
The following error occurred converting from sym to double:
Unable to convert expression containing remaining symbolic
function calls into double array. Argument must be
expression that evaluates to number.
Error in DiffEq_alt (line 13)
out(1) = f(ti);
Ultimately, I need to be able to be able to declare explicitly, but also treat it implicitly for when I differentiate the function with respect to . symbolic, differential equations, r2020b MATLAB Answers — New Questions
How can i bring this equation into matlab?
Hi, I want to make a equation solver with matlab.
what i want to make is attatched down below.
here, i have a thousand of data point with alpha and temperature.
also i have A, E, and R value.
here, what i tried is like this.
g_alpha = A/beta*cumtrapz(exp(-E./(R*T(2:length(T),:))));
and
n = 2;
G_alpha = [];
while n < 1000;
g_alpha = A/beta*int(exp(-E./(R*T(n+1,:))),[T(2,:) T(n+1,:)]);
G_alpha = [G_alpha; g_alpha];
n = n + 1;
end
but both of these aren’t work well.
do i miss something?
can anyone help me to make this completely?Hi, I want to make a equation solver with matlab.
what i want to make is attatched down below.
here, i have a thousand of data point with alpha and temperature.
also i have A, E, and R value.
here, what i tried is like this.
g_alpha = A/beta*cumtrapz(exp(-E./(R*T(2:length(T),:))));
and
n = 2;
G_alpha = [];
while n < 1000;
g_alpha = A/beta*int(exp(-E./(R*T(n+1,:))),[T(2,:) T(n+1,:)]);
G_alpha = [G_alpha; g_alpha];
n = n + 1;
end
but both of these aren’t work well.
do i miss something?
can anyone help me to make this completely? Hi, I want to make a equation solver with matlab.
what i want to make is attatched down below.
here, i have a thousand of data point with alpha and temperature.
also i have A, E, and R value.
here, what i tried is like this.
g_alpha = A/beta*cumtrapz(exp(-E./(R*T(2:length(T),:))));
and
n = 2;
G_alpha = [];
while n < 1000;
g_alpha = A/beta*int(exp(-E./(R*T(n+1,:))),[T(2,:) T(n+1,:)]);
G_alpha = [G_alpha; g_alpha];
n = n + 1;
end
but both of these aren’t work well.
do i miss something?
can anyone help me to make this completely? integration, data point, int, integral, data set, cumtrapz, trapz MATLAB Answers — New Questions
multivariate regression with multi dimensional variables
Dear Reader,
I’m having trouble with implementing a regression.
I have the following:
I have a 3D matrix results_demands(24,1,n) and a 3D matrix results_han(24,3,n)
Where 24 are the time steps and n are the observations.
I want to model the regression between the (24,1) vector results_demands and (24,3) matrix results_han
What I already tried is splitting up the results_han such that I have a matrix with n rows(observations) and 3 columns and every input is a (24,1) vector.
So that we have 3 response variables and 1 explanatory variable(results_demands) all variables in form of a vector.
How do I need to implement such extra dimensional case.
A visualization of the 3D matrices.
results_han : (24,3,n):
[ [vec_i] [vec_i] [vec_i]
[vec_i] [vec_i] [vec_i]
………………….
…………………. ]
with vec_i a (24,1) column vector
results_demands: (24,1,n):
[ [vec_k]
[vec_k]
……….]
with vec_k a (24,1) column vector
Thank you in advance!Dear Reader,
I’m having trouble with implementing a regression.
I have the following:
I have a 3D matrix results_demands(24,1,n) and a 3D matrix results_han(24,3,n)
Where 24 are the time steps and n are the observations.
I want to model the regression between the (24,1) vector results_demands and (24,3) matrix results_han
What I already tried is splitting up the results_han such that I have a matrix with n rows(observations) and 3 columns and every input is a (24,1) vector.
So that we have 3 response variables and 1 explanatory variable(results_demands) all variables in form of a vector.
How do I need to implement such extra dimensional case.
A visualization of the 3D matrices.
results_han : (24,3,n):
[ [vec_i] [vec_i] [vec_i]
[vec_i] [vec_i] [vec_i]
………………….
…………………. ]
with vec_i a (24,1) column vector
results_demands: (24,1,n):
[ [vec_k]
[vec_k]
……….]
with vec_k a (24,1) column vector
Thank you in advance! Dear Reader,
I’m having trouble with implementing a regression.
I have the following:
I have a 3D matrix results_demands(24,1,n) and a 3D matrix results_han(24,3,n)
Where 24 are the time steps and n are the observations.
I want to model the regression between the (24,1) vector results_demands and (24,3) matrix results_han
What I already tried is splitting up the results_han such that I have a matrix with n rows(observations) and 3 columns and every input is a (24,1) vector.
So that we have 3 response variables and 1 explanatory variable(results_demands) all variables in form of a vector.
How do I need to implement such extra dimensional case.
A visualization of the 3D matrices.
results_han : (24,3,n):
[ [vec_i] [vec_i] [vec_i]
[vec_i] [vec_i] [vec_i]
………………….
…………………. ]
with vec_i a (24,1) column vector
results_demands: (24,1,n):
[ [vec_k]
[vec_k]
……….]
with vec_k a (24,1) column vector
Thank you in advance! multivariate regression, regression, mvregress MATLAB Answers — New Questions