How can I write and solve this equation? as a function??
Show older comments

1 Comment
Benjamin Thompson
on 10 Feb 2022
Solve the equation for what? Need more information, and the screenshot is a little difficult to read.
Accepted Answer
More Answers (4)
Cesar Cardenas
on 16 Mar 2022
1 Comment
Walter Roberson
on 16 Mar 2022
Kz = @(z) cs*net*sqrt(8*k*T)/3.14*mi;
That function accepts 0 or 1 parameters, and ignores the parameter and computes a constant.
Note: we recommend you use pi instead of 3.14 unless you have particular reason to approximate the value.
Cesar Cardenas
on 16 Mar 2022
0 votes
24 Comments
Star Strider
on 16 Mar 2022
The function argument is ‘z’
Kz = @(z) cs*net*sqrt(8*k*T)/3.14*mi;
however ‘z’ nowhere appears in the expression to be evaluated.
What do you want it to be a function of?
Cesar Cardenas
on 16 Mar 2022
Walter Roberson
on 16 Mar 2022
Does cs vary with z? Does net vary with z? Does k vary with z? Does T vary with z? Does mi vary with z? Does the precision of pi that you use vary with z?
Cesar Cardenas
on 16 Mar 2022
Star Strider
on 17 Mar 2022
What is
?
Walter Roberson
on 17 Mar 2022
I do not not see any z in the ν definition. ν might change with altitude but which terms are constant with altitude and which vary with altitude?
Cesar Cardenas
on 17 Mar 2022
Star Strider
on 17 Mar 2022
‘What changes with altitude is n. The idea is to find the max. value of v1,2 as n varies within the 105-109 km range.’
The ‘v12’ variable is apparently a linear function of ‘n’ so the maximum value of ‘v12’ will be at the maximum value of ‘n’, unless other variables in the equation also change with altitude.
Cesar Cardenas
on 18 Mar 2022
Walter Roberson
on 19 Mar 2022
That appears to be an unrelated question.
Cesar Cardenas
on 20 Mar 2022
Star Strider
on 20 Mar 2022
I don’t believe it is.
There’s a
term in the denominator of the second term, that is then mulitplied by
so they should cancel out. Either that, or there is a typographical error in the second term.
I was curious about which power operation would be fastest. The three possibilities are ^(-1./2) (matrix power), .^(-1./2) (power), and 1/sqrt() (potentially using hardware square root).
Conclusions are a bit tricky.
If you look at the below code, notice I discard the first few samples. When you do not do that, then right at the beginning you get some timings that are much higher.
If you look at the graph below, notice there is an isolated large peak for ^ and another for .^ . In my tests up to N = 1000, it was not unusual to see those at isolated places, especially for ^ -- for some reason the ^ operator seems more "bursty" than the others, which I have no explanation for at the moment (because it should devolve to the same code as .^ for the case of scalars). If you use movmedian() with a mean of 3 then those peaks disappear.
You can see from the bottom half of the plot that the timings are pretty variable for the three different operations, with none of them being a clear winner. So we have to look at something like the mean() to talk about the statistical behaviour.
In my tests, most of the time ^ was slightly slower on average. That is not unexpected, as it has to do an extra step to determine whether to use scalar behaviour. Occasionally .^ shows up slower on average, which I suspect is due to those occasional large bursts.
In my tests, 1/sqrt() was almost always faster on average; with N = 1000, this becomes more obvious.
%initialize
N = 300;
t_mpower = zeros(N,1); t_power = zeros(N,1); t_sqrt = zeros(N,1);
%time
for K = 1 : N; d = rand(); start = tic; d^(-1./2); t = toc(start); t_mpower(K) = t; end
for K = 1 : N; d = rand(); start = tic; d.^(-1./2); t = toc(start); t_power(K) = t; end
for K = 1 : N; d = rand(); start = tic; 1./sqrt(d); t = toc(start); t_sqrt(K) = t; end
%discard "warm-up"
t_mpower(1:9) = []; t_power(1:9) = []; t_sqrt(1:9) = [];
%display
format long g
[mean(t_mpower), mean(t_power), mean(t_sqrt)]
plot(([t_mpower, t_power, t_sqrt]))
legend({'\^', '.\^', '1/sqrt'})
Walter Roberson
on 20 Mar 2022
log(d^(-1./2)./(5*b))
Note that that should be the same as
-log(5 .* b .* sqrt(d))
which could potentially be further decomposed (might be able to pre-calculate parts of that, depending what is varying.)
Cesar Cardenas
on 20 Mar 2022
Cesar Cardenas
on 20 Mar 2022
Cesar Cardenas
on 20 Mar 2022
It appears to be coded correctly (although not the way I would code it). That aside, the plot appear to be appropriate, although stress fields not an area of my expertise.
x=linspace(-5*10^9,5*10^9,101);
y=linspace(-5*10^9,-1*10^9,101);
G=27.7*10^9;
b=0.286*10^-9;
v=0.334;
[x,y]=meshgrid(x,y);
sxx=(-G*b)/(2*pi*(1-v))*y.*(3*x.^2+y.^2)./(x.^2+y.^2).^2;
syy=(G*b)/(2*pi*(1-v))*y.*(x.^2-y.^2)./(x.^2+y.^2).^2;
sxy=(G*b)/(2*pi*(1-v))*x.*(x.^2-y.^2)./(x.^2+y.^2).^2;
figure
surfc(x,y,sxx);
title('Plot of sxx');
figure;
surfc(x,y,syy);
title('Plot of syy');
figure;
surfc(x,y,sxy);
title('Plot of sxy');
.
Cesar Cardenas
on 21 Mar 2022
As always, my pleasure!
x=linspace(-5*10^9,5*10^9,101);
y=linspace(-5*10^9,-1*10^9,101);
G=27.7*10^9;
b=0.286*10^-9;
v=0.334;
[x,y]=meshgrid(x,y);
sxx=(-G*b)/(2*pi*(1-v))*y.*(3*x.^2+y.^2)./(x.^2+y.^2).^2;
syy=(G*b)/(2*pi*(1-v))*y.*(x.^2-y.^2)./(x.^2+y.^2).^2;
sxy=(G*b)/(2*pi*(1-v))*x.*(x.^2-y.^2)./(x.^2+y.^2).^2;
figure
contourf(x,y,sxx);
title('Plot of sxx');
figure;
contourf(x,y,syy);
title('Plot of syy');
figure;
contourf(x,y,sxy);
title('Plot of sxy');
.
Cesar Cardenas
on 21 Mar 2022
I don’t understand.
My best guess —
x=linspace(-5*10^9,5*10^9,101);
y=linspace(-5*10^9,-1*10^9,101);
G=27.7*10^9;
b=0.286*10^-9;
v=0.334;
[x,y]=meshgrid(x,y);
sxx=(-G*b)/(2*pi*(1-v))*y.*(3*x.^2+y.^2)./(x.^2+y.^2).^2;
syy=(G*b)/(2*pi*(1-v))*y.*(x.^2-y.^2)./(x.^2+y.^2).^2;
sxy=(G*b)/(2*pi*(1-v))*x.*(x.^2-y.^2)./(x.^2+y.^2).^2;
figure
contourf(x,y,sxx, 10);
xlim([-50 50])
colormap(turbo(10))
title('Plot of sxx');
figure;
contourf(x,y,syy, 10);
xlim([-50 50])
colormap(turbo(10))
title('Plot of syy');
figure;
contourf(x,y,sxy, 10);
xlim([-50 50])
colormap(turbo(10))
title('Plot of sxy');
.
Cesar Cardenas
on 21 Mar 2022
Star Strider
on 21 Mar 2022
I do not understand ‘coordinate range of [-50, 50] ’
What coordinates does this refer to?
Cesar Cardenas
on 22 Mar 2022
0 votes
1 Comment
Star Strider
on 22 Mar 2022
I’m still lost.
This is not an area of my expertise.
Perhaps re-defining ‘x’ and ‘y’ in the earlier code will do what you want.
Cesar Cardenas
on 27 Mar 2022
0 votes
12 Comments
Cesar Cardenas
on 27 Mar 2022
Star Strider
on 27 Mar 2022
Does ‘radical’ mean ‘root’ or decimal fraction?
Cesar Cardenas
on 27 Mar 2022
Walter Roberson
on 27 Mar 2022
sym() applied to a floating point number attempts to find fractions and square roots and pi
@Walter Roberson — Thank you! (I was off editing another answer.)
Still not certain.
The root of
is
is format long
sqrt(1/2)
The square of
is of course
.
is of course
..
Cesar Cardenas
on 29 Mar 2022
Star Strider
on 29 Mar 2022
I have no idea.
This is far from the original topic, and not an area of my expertise.
Walter Roberson
on 29 Mar 2022
v is a vector, so m.*v is a vector and v./abs(q) is a vector. FB1 is a vector and vector .* vector is a vector.
not sure how I can get a single value for rl??
Look at your equation. The F is underlined, indicating that the result is expected to be a vector, not a scalar.
Cesar Cardenas
on 31 Mar 2022
Cesar Cardenas
on 31 Mar 2022
Cesar Cardenas
on 31 Mar 2022
Categories
Find more on MATLAB Report Generator 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!





























