Funktion for a floating masspoint in 3D
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hey guys,
I´m new to matlab and I want you to ask you some questions.
First of all, I want to plot a floating masspoint on a 3D surface, so I try to figure out how to get the gradient, angle of the surface and at last but not least to get a differential equation.
My code looks like this:
%% paramter
h=0.0002; %
g=-9.81; %gravity
u=0.2; %friction
x0=-12;
y0=-12;
%% gradienten
fgradx = ((x0+h,y0)-(x0-h,y0))/2*h;
fgrady = ((x0,y0+h)-(x0,y0-h))/2*h;
%% angle
winkelx = atan((boden(x + h, c) - boden(x - h, c))/(2*h));
winkely = atan((boden(y + h, c) - boden(y - h, c))/(2*h));
%% Differential Equation
F=[Y(2);Y(3);cos(winkelx)*((sin(winkelx)*g*m)-(cos(winkelx)*m*g*u));cos(winkely)*((sin(winkely)*g*m)-(cos(winkely)*m*g*u))];
So I want you to know, if the code is fine or if i messed up. Would be nice, if you can give me some tips :).
Have a nice day.
Risposte (1)
Zuber Khan
il 26 Set 2024
Hi,
I understand that you are trying to write custom code to plot a floating masspoint on a 3D surface in MATLAB. There are a few aspects of the provided code that would need some adjustments, as outlined below:
- I see that you are using "boden" function but its implementation is missing. You would need to define it with appropriate logic to ensure that there are no run-time errors.
- Further, all the variables should be defined. For instance, 'm', 'c' and 'u' are not defined.
- The gradient calculations should use function calls, not tuples. Also, while the formula may work for 2D planes, it might fail for a 3D surface. Therefore, instead of writing custom code for gradient evaluation, you can use the functions present in Symbolic Math Toolbox for the same. To know more about how to calculate gradient in MATLAB, you can have a look at the following documentation:
- Further, the differential equation in the code is represented in the vectorized form which might cause issues while solving it. Therefore, in order to have better understanding about representation of differential equations and solving them, you can refer to the following documentation:
Lastly, you can use the "surf" function to create a three-dimensional surface plot. For more information, kindly refer to the following link:
I hope it clarifies your doubts.
Regards,
Zuber
0 Commenti
Vedere anche
Categorie
Scopri di più su Eigenvalue Problems 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!