Code an equation in MATLAB
Mostra commenti meno recenti

In matlab, I write the following code to the above equation as follows
ri = sqrt(psi_coordinates.^2+theta_coordinates.^2);
A = sum((ri*delta_epsilon)/2);
V = delta_z*sum(A);
But the result I obtained is not correct. Can anyone comment if I made some mistake please ?
Thank you .
27 Commenti
Walter Roberson
il 7 Mag 2022
you forgot the square root
HN
il 7 Mag 2022
Dyuman Joshi
il 7 Mag 2022
I am assuming m is the number of rows and n is the number of columns.
If so, then you have to use sum((ri*delta_epsilon)/2,2) while defining A to get the row-wise sum.
Jeffrey Clark
il 7 Mag 2022
Where is the sqrt in computation of ri?
ri = sqrt(psi_coordinates.^2+theta_coordinates.^2);
Jeffrey Clark
il 7 Mag 2022
The last equation in the image is missing a closing paren in the first definition of V before simplification; I assume the open paren should be moved before the second summation and another close paren added before the simplification of V. V is supposed to be calculating a scaler sum of sums, which must be implying that the ri and A are to be working on only one of the dimensions of phi and theta, in MATLAB the sums of the ri and A will be only on one of them, and the V sum should then be on the other. The calculation of the sum in A in MATLAB will be on one of the dimensions. Since you didn't tell MATLAB which dimention the sum is on could you be calculating with the delta_epsilon and delta_z affecting the wrong dimentional data?
Dyuman Joshi
il 10 Mag 2022
While defining delta_epsilon, what is the value of m?
Dyuman Joshi
il 10 Mag 2022
Modificato: Dyuman Joshi
il 10 Mag 2022
Try this
r = (th.^2+psi.^2).^0.5;
delz=0.0125;
deleps=0.0622;
A = sum(r*deleps*delz/2,2); %row sum
V = delz*sum(A)
HN
il 10 Mag 2022
Dyuman Joshi
il 10 Mag 2022
Modificato: Dyuman Joshi
il 10 Mag 2022
Sorry, it was ignored because of my mistake. I forgot to take it into account. I have edited it.
Did you take element wise sqrt? Like I have, in the edit?
HN
il 10 Mag 2022
Dyuman Joshi
il 10 Mag 2022
How are you inputting the data? I can try it as well and check.
HN
il 10 Mag 2022
Dyuman Joshi
il 10 Mag 2022
Modificato: Dyuman Joshi
il 10 Mag 2022
@HN, I am getting 81*102 matrices while loading from both the text files.

HN
il 10 Mag 2022
Dyuman Joshi
il 10 Mag 2022
Idk, but that's what I got. Even changing delesp according to m, brought only a minimum change in the value of V.
How do you get the value of V btw?
Jeffrey Clark
il 11 Mag 2022
In your last code segment, next-to-last line references Delta_z not delta_z what is going on here? Retyping code incorrectly for these comments or somewhere have a capital D delta?
Jeffrey Clark
il 11 Mag 2022
So the line below may not be doing what you expect due to rounding to computer precision; although there seems to be more missing than provided in your edited part of the program, this for loop will dictate the size of work_points and work_surf but I don't know to what extent the psi and th since z_slices value isn't given and may not jive with the generated work_surf:
for meridian = 0 : delta_meridian : 2*pi
HN
il 17 Mag 2022
Jeffrey Clark
il 17 Mag 2022
- I think you could be helped most by uploading the complete MATLAB program
- in your 10 May 2022 at 7:53 post, you added a delta_z in the calculation of A which wasn't in your original post
- in your 10 May 2022 at 20:22 post, in the first if..elseif..else statement the else will never execute because the elseif includes the negated if clause and an or (||) with another clause that won't be tested - perhaps you intended an and (&&) in the elseif?
- based on what you did provide, phi and th would not be matrices just vectors, so the sums don't make sense
The program seems too complex for something that that that just needs to create some sort of angle or sine space mesh.
Dyuman Joshi
il 18 Mag 2022
What is the unit of meridian? Degrees/Radians?
size_temp = size(work_surf);
work_surf = work_surf(:,2:size_temp(2));
size_temp = size(work_surf);
psi_coordinates = psi_coordinates';
theta_coordinates = theta_coordinates';
psi = psi_coordinates';
th = theta_coordinates';
This 2 snips of code can be modified to remove redundancy
HN
il 18 Mag 2022
HN
il 18 Mag 2022
Risposte (0)
Categorie
Scopri di più su Entering Commands in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

