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

33 views (last 30 days)
  1 Comment
Benjamin Thompson
Benjamin Thompson on 10 Feb 2022
Solve the equation for what? Need more information, and the screenshot is a little difficult to read.

Sign in to comment.

Accepted Answer

Star Strider
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.
.
  53 Comments
Cesar Cardenas
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
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

Sign in to comment.

More Answers (4)

Cesar Cardenas
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)
  1 Comment
Walter Roberson
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.

Sign in to comment.


Cesar Cardenas
Cesar Cardenas on 16 Mar 2022
Right thanks, how can I change it to accept any value? Thanks much
  24 Comments
Cesar Cardenas
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
Star Strider on 21 Mar 2022
I do not understand ‘coordinate range of [-50, 50]
What coordinates does this refer to?

Sign in to comment.


Cesar Cardenas
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.
  1 Comment
Star Strider
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.

Sign in to comment.


Cesar Cardenas
Cesar Cardenas on 27 Mar 2022
How can I convert this value 0.6667 to a fraction? Thanks
  12 Comments
Cesar Cardenas
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
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

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!