Using subs To Solve sims Equation with Points on A Grid
Show older comments
Hi,
I'm trying to use subs to subsitute x and y coordinates into a symbolic equation so I can solve it for the value at each coordinate. Below is how my code is currently sctructured.
%% Creating Fluid Equations
syms x y
vel_x = sin(x) + cos(y);
vel_y = cos(x)^2 + sin(y)^0.5;
pressure = 101300 * (x*exp(y));
density = 1.2 * (x^2 + y^0.5);
%% Plotting Fluid Equations
x_input = 0:0.1:10;
y_input = 0:0.1:10;
[x_coord, y_coord] = meshgrid(x_input, y_input);
% Subsitute symbolic variables with x and y arrays and turn into array of
% doubles
vel_x = double(subs(vel_x, [x, y], {x_coord, y_coord}));
vel_y = double(subs(vel_y, [x, y], {x_coord, y_coord}));
pressure = double(subs(pressure, [x, y], {x_coord, y_coord}));
density = double(subs(density, [x, y], {x_coord, y_coord}));
surf(x_input, y_input, vel_x)
This code is already taking 5 whole seconds to run and ideally I'd like to increase the density of coordinates. I was trying to stay away from using for loops wich is how I ended up using meshgrid and subs instead. How can I make this much more efficient?
Any advice would be much appreciated thank you!
1 Comment
Walter Roberson
on 16 Oct 2023
See matlabFunction
Answers (0)
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!