- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
error in 3d plotting.
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
% Define the equations for r(x) and theta(x) soln
%fun = @(x, y, mu, lambda, ke, ko) [y(2); (-x * y(2) + y(1) - ke^2 * x^2 / (2 * mu + lambda) * y(1) + ko^2 * x^2 * y(3) / (2 * mu + lambda)) / x^2; ...
% y(4); (-x * y(4) + y(3) - ko^2 / mu * x^2 * y(1) - ke^2 / mu * x^2 * y(3)) / x^2];
% Define the equations as x*r(x) and x*theta(x) soln
fun = @(x, y, mu, lambda, ke, ko) [x * y(2);
(-x^2 * y(2) + x * y(1) - (ke^2 * x^4) / (2 * mu + lambda) * y(1) + (ko^2 * x^4 * y(3)) / (2 * mu + lambda)) / x^2;
x * y(4);
(-x^2 * y(4) + x * y(3) - (ko^2 * x^4) / mu * y(1) - (ke^2 * x^4) / mu * y(3)) / x^2];
% Define the initial conditions
initialConditions = [0.2; 0; 0; 0]; % r(0.75) = 0.1625, r'(0.75) = 0, Theta(0.75) = 0, Theta'(0.75) = 0
% Define the parameter ranges
mu_r_range = linspace(3, 20, 12);
lambda_r_range = linspace(50, 100, 10);
mu_theta_range = linspace(3, 20, 12);
lambda_theta_range = linspace(50, 100, 10);
ke_range = linspace(0.0001, 0.6, 10);
ko_range = linspace(0.0001, 0.6, 10);
% Initialize arrays to store peak extremum values
peak_r = zeros(length(ke_range), length(ko_range));
peak_theta = zeros(length(ke_range), length(ko_range));
% Solve the differential equations for each combination of parameters
for m = 1:length(ke_range)
for n = 1:length(ko_range)
ke = ke_range(m);
ko = ko_range(n);
% Initialize arrays to store extremum values for each solution
extremum_r = zeros(size(mu_r_range));
extremum_theta = zeros(size(mu_theta_range));
for i = 1:length(mu_r_range)
for j = 1:length(lambda_r_range)
for k = 1:length(mu_theta_range)
for l = 1:length(lambda_theta_range)
mu_r = mu_r_range(i);
lambda_r = lambda_r_range(j);
mu_theta = mu_theta_range(k);
lambda_theta = lambda_theta_range(l);
% Solve the differential equations
[x, y] = ode45(@(x, y) fun(x, y, mu_r, lambda_r, ke, ko), [0.75, 210], initialConditions);
% Calculate extremum values for r(x) and Theta(x)
extremum_r(i) = max(abs([max(y(:, 1)), min(y(:, 1))])); % Absolute maximum between max and min
extremum_theta(k) = max(abs([max(y(:, 3)), min(y(:, 3))])); % Absolute maximum between max and min
end
end
end
end
% Store the peak extremum values for each combination of ke and ko
peak_r(m, n) = max(extremum_r);
peak_theta(m, n) = max(extremum_theta);
end
end
% Plot the peak extremum values of r(x) for each combination of ke and ko
figure;
surf(ke_range, ko_range, peak_r);
xlabel('ke');
ylabel('ko');
zlabel('Peak Extremum Value of r(x)');
title('Peak Extremum Values of r(x)');
% Plot the peak extremum values of Theta(x) for each combination of ke and ko
figure;
surf(ke_range, ko_range, peak_theta);
xlabel('ke');
ylabel('ko');
zlabel('Peak Extremum Value of Theta(x)');
title('Peak Extremum Values of Theta(x)');
Want to 3d plot of x*r(x) and x*theta(x) with respect to ke and ko. But not getting any peak in the 3d plots as it was mentioned in the code. Any suggestions with possible errors?
0 Commenti
Risposta accettata
Hassaan
il 19 Mar 2024
% Define the ODE function according to your problem statement.
% It's important to ensure that this function correctly models the physical or mathematical system.
fun = @(x, y, mu, lambda, ke, ko) [x * y(2);
(-x^2 * y(2) + x * y(1) - (ke^2 * x^4) / (2 * mu + lambda) + (ko^2 * x^4 * y(3)) / (2 * mu + lambda)) / x^2;
x * y(4);
(-x^2 * y(4) + x * y(3) - (ko^2 * x^4) / mu * y(1) - (ke^2 * x^4) / mu * y(3)) / x^2];
% Define your initial conditions and ensure they are suitable for the problem.
initialConditions = [0.2; 0; 0; 0];
% Define parameter ranges. Ensure these ranges are logical for your problem.
ke_range = linspace(0.0001, 0.6, 10);
ko_range = linspace(0.0001, 0.6, 10);
% Preallocate matrices to store results for efficiency.
peak_r = zeros(length(ke_range), length(ko_range));
peak_theta = zeros(length(ke_range), length(ko_range));
% Loop through each combination of parameters.
for m = 1:length(ke_range)
for n = 1:length(ko_range)
ke = ke_range(m);
ko = ko_range(n);
% Define material properties or other parameters if they vary.
mu = 10; % Example value
lambda = 50; % Example value
% Solve the differential equations over a defined x domain.
% Adjust the x domain [0.75, 210] as necessary for your problem.
[x, y] = ode45(@(x, y) fun(x, y, mu, lambda, ke, ko), [0.75, 210], initialConditions);
% Extract and store the peak values for r(x) and theta(x).
% This method captures the peaks in the results for each ke, ko pair.
peak_r(m, n) = max(abs(y(:, 1)));
peak_theta(m, n) = max(abs(y(:, 3)));
end
end
% Visualization
% Create 3D surface plots to visualize how peak values change with ke and ko.
figure;
surf(ke_range, ko_range, peak_r');
title('Peak Extremum Values of r(x)');
xlabel('ke');
ylabel('ko');
zlabel('Peak r(x)');
colorbar;
figure;
surf(ke_range, ko_range, peak_theta');
title('Peak Extremum Values of Theta(x)');
xlabel('ke');
ylabel('ko');
zlabel('Peak Theta(x)');
colorbar;
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
Feel free to contact me.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su AI for Audio in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!