# How can I write and solve this equation? as a function??

11 views (last 30 days)
Cesar Cardenas on 10 Feb 2022
Commented: Cesar Cardenas on 31 Mar 2022
Benjamin Thompson on 10 Feb 2022
Solve the equation for what? Need more information, and the screenshot is a little difficult to read.

Star Strider on 10 Feb 2022
Possibly, after first providing values for the constants:
T(z,z0,Tz0,Tinf) = Tinf - (Tinf - Tz0).*exp(z-z0); % Function
zsol = fzero(@(z)T(z,z0,Tz0,Tinf), rand) % Correct Call To It (Here Using 'fzero', Can Be Any Function)
See the documentation on Anonymous Functions for details.
.
Cesar Cardenas on 20 Feb 2022
Thanks, basically, for q(h) I have this:
I do not have errors and it runs well when the other parameters are defined.
q_max = 0.5;
%h = 139.6;
h_max = 198.369;
H = 35.6757;
x = 15;
format long g
qh = @(h) q_max.* exp((1 - (h - h_max)./H - sec(x)).*exp(-(h-h_max)./H));
qh (198)
I have this other equation for q(h) as in this case it depends on h and x, at first I get some erros but now it seems to run well, but sure it would be well defined?
q_max = 0.5;
%h = 198;
h_max = 198.369;
H = 35.6757;
%x = 15;
format long g
qh = @(h,x) q_max.*exp((1 - (h - h_max)./H - sec(x)).*exp(-(h-h_max)./H));
qh (198,15)
and for q_max as you mention in this comment I defined like this for instance for h = 100 and get errors
format long g
q_max = @(h) q(h) ./exp((1 - (h - h_max)./H - sec(x)).*exp(-(h-h_max)./H))
q_max(100)
Index exceeds the number of array elements. Index must not exceed 1.
Thanks much.
Walter Roberson on 20 Feb 2022
q is a variable that is an array; it is not a function at that point.
We do not see what q is in your code.
qh = @(h,x) q_max.*exp((1 - (h - h_max)./H - sec(x)).*exp(-(h-h_max)./H));
Okay, you made qh a function of h and x. That potentially makes sense
q_max = @(h) q(h) ./exp((1 - (h - h_max)./H - sec(x)).*exp(-(h-h_max)./H))
You made q_max a function of h but not of x . That feels a bit inconsistent after the definition for qh

Cesar Cardenas on 16 Mar 2022
Not sure what I'm not doing right as I'm not getting any change when the value is varied?? any help will be appreciated. Thanks.
net = 9.37e4;
T = 183;
mi= 5.31e-26;
k = 1.38e-23;
cs = 1.1304e-18;
format long g
Kz = @(z) cs*net*sqrt(8*k*T)/3.14*mi;
Kz(433)
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
Right thanks, how can I change it to accept any value? Thanks much
Cesar Cardenas on 21 Mar 2022
Thanks much. Maybe I was not so clear, the idea is to use the contour plot in the coordinate range of [-50, 50] and I think the solution would be similar to the one in the previous comment. Not sure how to do it.
Thanks so much
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
Thanks much I think your approach here comment. is pretty similar to the below image. I think the coordinate range may refer to something like this graph...not sure though. Thanks much.
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
How can I convert this value 0.6667 to a fraction? Thanks
Cesar Cardenas on 31 Mar 2022
How can I calculate the magnitude of this vector:
v = [2 30 0]*10^-3,, it is to 10^-3 not sure how to add it to the code
v = [2: 30: 0];
sv = v.* v; %the vector with elements
% as square of v's elements
dp = sum(sv); % sum of squares -- the dot product
mag = sqrt(dp); % magnitude
disp('Magnitude:');
disp(mag);
Cesar Cardenas on 31 Mar 2022
@Walter Roberson thank you regarding this comment. Basically here what I need to is find V perpendicular as shown here;
So first I did this:
%Magnitude of B
B = [2 30 0];%uniform magnetic field
norm(B*10^-3)
Then, this; to find V parallel,
dot(v,B)
So, would it be a nice approach? or how can I work this out? Thanks much